MySQL设置外键
程序员文章站
2022-05-31 23:44:01
...
CREATE TABLE SPJ(
SNO CHAR(2) NOT NULL ,
PNO CHAR(2) NOT NULL ,
JNO CHAR(4) NOT NULL ,
QTY INT NOT NULL ,
PRIMARY KEY (SNO,PNO,JNO,QTY)
);
# 设置外键
ALTER TABLE SPJ ADD CONSTRAINT fk_SPJ_SS
FOREIGN KEY (SNO) REFERENCES SS (SNO);
ALTER TABLE SPJ ADD CONSTRAINT fk_SPJ_P
FOREIGN KEY (PNO) REFERENCES P (PNO);
ALTER TABLE SPJ ADD CONSTRAINT fk_SPJ_J
FOREIGN KEY (JNO) REFERENCES J (JNO);
上一篇: sql杂记:一些坑和数据库恢复
下一篇: npm包发布流程 正式包和测试包beta