打开设计表,在对应的栏位填写相应的内容。其中FK_deptno是限制名
ALTER TABLE dept ADD PRIMARY KEY(deptno)
ALTER TABLE emp ADD CONSTRAINT FK_deptno FOREIGN KEY(deptno) REFERENCES dept(deptno)
ALTER TABLE emp DROP FOREIGN KEY FK_deptno
外键约束导致的主从表问题:
DELETE FROM dept where deptno=‘40‘;
UPDATE dept SET deptno=‘90‘ WHERE deptno=‘40‘
INSERT INTO dept VALUES(‘80‘,‘MANAGEMENT‘,‘SYNEY‘)
DELETE FROM emp WHERE deptno = ‘40‘
INSERT INTO emp values(‘8788‘,‘wang‘, ‘ENGINEER‘,‘04‘,‘7781‘,‘1999-09-08‘, 999.99,99.9, ‘50‘)
UPDATE emp SET deptno = ‘50‘ WHERE deptno = ‘20‘
原文:https://www.cnblogs.com/huainanhai/p/11025412.html