Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

constraint in mySQL

Status
Not open for further replies.

gwp

Programmer
Jan 15, 2003
4
SE
Hi

Isn´t this constraints working in mySQL?

query = "CREATE TABLE Employee (";
query += " EmployeeID INT AUTO_INCREMENT PRIMARY KEY ";
query += " , CivicNr CHAR(11) UNIQUE NOT NULL ";
query += " , Name VARCHAR(50) NOT NULL ";
query += " , Salary INT NOT NULL ";
query += " , CONSTRAINT CivicNr CHECK (CivicNr LIKE '______-____') ";
query += " , CONSTRAINT Salary CHECK (Salary > 12500) ";
query += " ) ";

The table is created but when I insert f.ex Salary = 10000 it´s stored without any messages. Shouldn´t mySQL prevent this and throw an exception?

Thanks in advance, regards GWP
 
taken from the documentation:

The FOREIGN KEY, CHECK, and REFERENCES clauses don't actually do anything, except for InnoDB type tables which support ADD CONSTRAINT FOREIGN KEY (...) REFERENCES ... (...). Note that InnoDB does not allow an index_name to be specified.

So if you use MyISAM nothing will happen at all, if you use InnoDB only foregn keys can be created.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top