簡體   English   中英

嘗試在sql oracle 11g中創建表

[英]Try to create a table in sql oracle 11g

我正在嘗試創建一個表,但是它一直給我錯誤消息味精“無效標識符”,我反復搜索,無法弄清楚我的代碼出了什么問題.....請幫助.....這里是我的代碼。

create table ownership
(
   oID number not null,
   dID number not null,
   start date,
   end date,
   primary key (oID,dID)
   foreign key (oID) references owner(oID),
   foreign key (dID) references dogs(dID)
);

我從nyc打開數據導入了dogs表,並且還創建了所有者表.....表名沒有錯,我一遍又一遍地檢查,表所有者中的oID是主鍵,表狗中的dID也是如此。 ....我試圖刪除不為null的約束,錯誤消息為msg,我試圖將pk_ownership約束放在主鍵之前,但仍然收到相同的錯誤消息.....我真的不知道為什么...這是對於一個學校項目,我是sql的超級新手,這是我做sql的第二天……如果我的問題很愚蠢,請裸露我.....謝謝!

您有兩個主要錯誤:

  • 您缺少逗號(在主數據庫上)
  • start是保留字

end也是一個關鍵字,因此我也建議不要使用它。

我建議類似的東西:

create table ownership (
   oID number not null,
   dID number not null,
   ownership_start date,
   ownership_end date,
   primary key (oID, dID),
   foreign key (oID) references owner(oID),
   foreign key (dID) references dogs(dID)
);

在Oracle中, start是保留字。 如果引用它,則可以使用它,如下所示:

create table ownership
(
   oID number not null,
   dID number not null,
   "start" date,
   end date,
   primary key (oID,dID),
   foreign key (oID) references owner(oID),
   foreign key (dID) references dogs(dID)
);

或者...您可以簡單地使用其他名稱,例如start_ownership

PS:您也有一個較小的語法錯誤。 您忘記了主鍵定義末尾的逗號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM