ALTER TABLE t_productinfo1
ADD CONSTRAINT fk_pro FOREIGN KEY(Category)
REFERENCES categoryinfo(CategoryId)
ON DELETE CASCADE;
删除外键约束
ALTER TABLE t_productinfo1
DROP CONSTRAINT fk_pro;
条件约束
添加约束
CREATE TABLE custominfo
(CustomId varchar2(10),
Name varchar2(10),
Age number(2),
Gender varchar2(2),
Tel varchar2(11),
Address varchar2(100),
CONSTRAINT CHK_AGE CHECK(Age>=18 AND Age<=30)
);
ALTER TABLE custominfo
ADD CONSTRAINT chk_gender CHECK(Gender='男' or Gender='女');
移除约束
ALTER TABLE custominfo
DROP CONSTRAINT chk_gender;
ALTER TABLE orderinfo
ADD CONSTRAINT UNQ_CUSTOMID UNIQUE(CustomId);
ALTER TABLE orderinfo
DROP CONSTRAINT UNQ_CUSTOMID;
非空约束
CREATE TABLE managerinfo
(ManagerID varchar2(10),
LoginName varchar2(10) NOT NULL,
LoginPassword varchar2(10) NOT NULL,
Name varchar2(10),
Tel varchar2(11)
);
ALTER TABLE managerinfo
MODIFY Name NOT NULL;