SQL CHECK 约束
CREATE TABLE Salaries
(name VARCHAR(32) PRIMARY KEY,
sex CHAR(1) NOT NULL,
salary INTEGER NOT NULL,
CHECK (salary<200000));
CREATE TABLE Salaries
(name VARCHAR(32) PRIMARY KEY,
sex CHAR(1) NOT NULL,
salary INTEGER NOT NULL,
CONSTRAINT check_salary CHECK ( sex = '2' AND salary <= 200000 ));
update:
添加外键:
alter table book add constraint book_category foreign key (cid) references category(cid);