所以我正在学习一些SQL作为一个附带项目,因为我的SQL很烂。我有下表:
CREATE TABLE deliveries (
pid INTEGER,
FOREIGN KEY (pid) REFERENCES person_lives_at,
);
我想将其更改为这样的桌子:
CREATE TABLE deliveries (
pid INTEGER,
FOREIGN KEY (pid) REFERENCES employee,
);
我该如何实现?我正在使用Oracle SQL开发人员
由于您创建了一个没有名称的FK约束,因此Oracle分配了系统生成的名称,例如SYS_XXXXXX。要找到约束名称:
select constraint_name from all_Constraints
where table_name = 'DELIVERIES'
在我的测试案例中,它返回了" SYS_C0016779"。然后,我放下约束:
alter table deliveries drop constraint SYS_C0016779
然后添加新约束:
ALTER TABLE deliveries
ADD CONSTRAINT PID_EMP_FK -- or whatever you want to call it.
FOREIGN KEY (pid)
REFERENCES employee(pid); -- or whatever the name of the column is