gpt4 book ai didi

sql - ORA-00907 : Missing Right Parenthesis On Creating Foreign Key Oracle 12c

转载 作者:行者123 更新时间:2023-12-02 03:42:38 25 4
gpt4 key购买 nike

我想制作一张包含一个自动生成的主键和两个外键的表,但我遇到了此错误...

create table answers
( id number generated by default on null as identity primary key
, question_id number foreign key references questions(id)
, user_id number foreign key references users(id)
, answer varchar(1000)
, post_date date);

create table answers (id number generated by default on null as identity primary key, question_id number foreign key references questions(id), user_id number foreign key references users(id), answer varchar(1000), post_date date)

ERROR at line 1: ORA-00907: missing right parenthesis

然后,我尝试了这个:

create table answers
( id number generated by default on null as identity primary key
, question_id number foreign key (question_id) references questions(id)
, user_id number foreign key (user_id) references users(id)
, answer varchar(1000)
, post_date date );

create table answers
( id number generated by default on null as identity primary key
, question_id number foreign key (question_id) references questions(id)
, user_id number foreign key (user_id) references users(id)
, answer varchar(1000)
, post_date date )
*

ERROR at line 1: ORA-00907: missing right parenthesis

它仍然给出同样的错误!

但是,如果我分两步进行:

create table answers
( id number generated by default on null as identity primary key
, question_id number not null
, user_id number not null
, answer varchar(1000)
, post_date date );

Table created.

alter table answers
add foreign key (question_id) references questions(id) add foreign key (user_id) references users(id);

Table altered.

谁能帮我摆脱这个困境吗?

最佳答案

当将约束内联定义为列定义的一部分时,您不需要说外键:

create table answers
( id number generated by default on null as identity primary key
, question_id number references questions(id)
, user_id number references users(id)
, answer varchar(1000)
, post_date date);

祝你好运。

关于sql - ORA-00907 : Missing Right Parenthesis On Creating Foreign Key Oracle 12c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48045336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com