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

前端 未结 2 739
孤城傲影
孤城傲影 2021-01-21 23:39

I Want To Make a Table Which Include One Auto Generated Primary Key And Two Foreign Keys But I\'m Facing This Error...

create table answers
( id number generat         


        
相关标签:
2条回答
  • 2021-01-22 00:10

    When defining the constraint in-line as part of the column definition you don't need to say foreign key:

    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);
    

    Best of luck.

    0 讨论(0)
  • 2021-01-22 00:25

    you may define foreign keys at the bottom, non-adjacent to column names, like below :

    create table answers (
                          id number generated by default on null as identity primary key, 
                          question_id number, 
                          user_id number, 
                          answer varchar(1000), 
                          post_date date,
                          foreign key(question_id) references questions(id),
                          foreign key(user_id) references users(id)                            
                         );
    
    0 讨论(0)
提交回复
热议问题