【问题标题】:Foreign key constraint is not working in Oracle外键约束在 Oracle 中不起作用
【发布时间】:2016-05-26 22:29:30
【问题描述】:

我从 W3school 读到这个命令

P_Id int FOREIGN KEY REFERENCES Persons(P_Id)

将在 PLSQL 中工作,当我在 Sql Developer 上尝试此操作时,它引发了异常

ORA-00907: 缺少右括号

在此之后,我用以下命令替换了这个命令

P_Id int, 
CONSTRAINT fk_PerOrders FOREIGN KEY (P_Id) REFERENCES Persons(P_Id)

它成功了,我想问一下第一个命令是不是针对 oracle 还是我的 oracle 有问题。

【问题讨论】:

  • 不要使用 w3fools。它充满了错误
  • 谢谢 a_horse_with_no_name

标签: sql oracle ddl


【解决方案1】:

inline 约束的foreign key 部分无效。你只能使用references

create table x
(
  p_id integer references persons(p_id)
);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2022-12-22
  • 1970-01-01
  • 2019-07-15
  • 1970-01-01
  • 2011-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多