ORA-00907:缺少右括号在Oracle数据库中添加外键时出错[已关闭]

f2uvfpb9  于 2023-05-22  发布在  Oracle
关注(0)|答案(2)|浏览(194)

**关闭。**这个问题是not reproducible or was caused by typos。目前不接受答复。

此问题是由打印错误或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这一个是解决的方式不太可能帮助未来的读者。
2天前关闭。
Improve this question
我创建了一个表Department,如下所示:

create table department
(
    deptid int primary key,
    dname varchar(255)
);

deptid是主键。我添加了一个Employee表如下:

create table employee
(
    eid int primary key,
    ename varchar(255),
    deptid int foreign Key references dept_rudra(deptid)
);

我试图添加一个外键,但我得到以下错误。有人能给我指路吗?

to94eoyn

to94eoyn1#

错误的外键语法和错误的引用表名(如果表名为department,则不能引用dept_rudra)。

SQL> CREATE TABLE department
  2  (
  3     deptid   INT PRIMARY KEY,
  4     dname    VARCHAR (255)
  5  );

Table created.

您可以使用各种选项(inline、out-of-line、using alter table)-无论您选择什么,只要语法正确,都可以工作。

SQL> CREATE TABLE employee
  2  (
  3     eid      INT PRIMARY KEY,
  4     ename    VARCHAR (255),
  5     deptid   INT CONSTRAINT fk_ed REFERENCES department (deptid)
  6  );

Table created.

SQL> DROP TABLE employee;

Table dropped.

SQL> CREATE TABLE employee
  2  (
  3     eid      INT PRIMARY KEY,
  4     ename    VARCHAR (255),
  5     deptid   INT,
  6     --
  7     CONSTRAINT fk_ed FOREIGN KEY (deptid) REFERENCES department (deptid)
  8  );

Table created.

SQL> DROP TABLE employee;

Table dropped.

SQL> CREATE TABLE employee
  2  (
  3     eid      INT PRIMARY KEY,
  4     ename    VARCHAR (255),
  5     deptid   INT,
  6     --
  7     FOREIGN KEY (deptid) REFERENCES department (deptid)
  8  );

Table created.

SQL> DROP TABLE employee;

Table dropped.

SQL> CREATE TABLE employee
  2  (
  3     eid      INT PRIMARY KEY,
  4     ename    VARCHAR (255),
  5     deptid   INT
  6  );

Table created.

SQL> ALTER TABLE employee ADD CONSTRAINT fk_ed FOREIGN KEY (deptid)
  2    REFERENCES department (deptid);

Table altered.

SQL>
ddhy6vgd

ddhy6vgd2#

create table employee(
eid int primary key,
ename varchar(255),
deptid int,
foreign key (deptid) references department(deptid)
);

相关问题