arashi
06-03-2002, 04:44 AM
I'm using the latest version of MySQL on Mandrake for school. My lecturer said constraints can be included in the tables using the CONSTRAINT statement. But when I did a sample run of the table below, MySQL said there was an error with the salary constraint.
I'd be obliged someone could look at this code and tell me if there's anything wrong with it, or how to get around this problem with constraints. The MySQL docs don't have any info on the constraint statement, and I've read that MySQL isn't that good at enforcing them anyway. If so, how do MySQL developers get round that? Cheers!
[My lecturer's table BTW]
CREATE table Staff(
staffNo varchar(10)PRIMARY KEY,
sex CHAR(1),
CONSTRAINT sex_status CHECK(sex IN
('M','F'),
salary NUMERIC(9,2),
CONSTRAINT salary_range CHECK(salary
< 500000.00 AND salary > 0),
branchNo varchar(10) NOT NULL,
CONSTRAINT FK_staff_branchNo FOREIGN
KEY(branchNo) References Branch
(branchNo));
I'd be obliged someone could look at this code and tell me if there's anything wrong with it, or how to get around this problem with constraints. The MySQL docs don't have any info on the constraint statement, and I've read that MySQL isn't that good at enforcing them anyway. If so, how do MySQL developers get round that? Cheers!
[My lecturer's table BTW]
CREATE table Staff(
staffNo varchar(10)PRIMARY KEY,
sex CHAR(1),
CONSTRAINT sex_status CHECK(sex IN
('M','F'),
salary NUMERIC(9,2),
CONSTRAINT salary_range CHECK(salary
< 500000.00 AND salary > 0),
branchNo varchar(10) NOT NULL,
CONSTRAINT FK_staff_branchNo FOREIGN
KEY(branchNo) References Branch
(branchNo));