2013-04-09 62 views
-1

我正在運行這兩個命令來創建新表,但第二個創建表命令不斷給我錯誤。SQL創建表缺少圓括號

CREATE TABLE TEAMSTADIUM(
stadium_name varchar2(40) not null, 
stadium_max_capcity number(10) not null, 
stadium_field_serface varchar2(40) not null, 
stadium_year_built number(4) not null, 
stadium_location varchar2(40) not null, 
Primary KEY(stadium_name) 
) 


CREATE TABLE TEAMINFO(
team_name varchar2(40) not null, 
team_owner varchar2(40) not null, 
team_coach varchar2(40) not null, 
team_created Date() not null, 
PRIMARY KEY(team_name) 
foreign key(stadium_name) references TEAMSTADIUM(stadium_name) 
) 
+0

,請發表您的錯誤消息(你應該總是這樣做) – 2013-04-09 23:38:23

+0

我跑了第一個創建表命令,然後我得到的第二個 - ora-00907 – user1817081 2013-04-09 23:39:54

回答

1

TEAMINFO表引用TEAMSTADIUM.stadium_name後放;,但有自己的沒有這樣的列。添加它,確保它具有相同的數據類型作爲父表:

CREATE TABLE TEAMINFO(
    team_name varchar2(40) not null, 
    team_owner varchar2(40) not null, 
    team_coach varchar2(40) not null, 
    team_created Date not null, 
    -- Remove() ^^ 
    -- This column must exist in both tables 
    stadium_name varchar2(40) not null, 
    PRIMARY KEY(team_name), 
    -- missing comma  ^^ 
    foreign key(stadium_name) references TEAMSTADIUM(stadium_name) 
) 

運用上述三種修改後,它會正確執行:如果這不是你的問題http://sqlfiddle.com/#!4/883a4

0

嘗試使用Date not null;和茶几的每個)

CREATE TABLE TEAMINFO(
    stadium_name varchar2(40) not null, 
    team_name varchar2(40) not null, 
    team_owner varchar2(40) not null, 
    team_coach varchar2(40) not null, 
    team_created Date not null, 
    PRIMARY KEY(team_name), 
    foreign key(stadium_name) references TEAMSTADIUM(stadium_name) 
); 
+0

試過了,仍然沒有運氣。 – user1817081 2013-04-09 23:42:21

+0

@ user1817081看到這一行'外鍵(stadium_name)引用TEAMSTADIUM(stadium_name)'在最後一行丟失了cuote並且場館名稱不存在於表'TEAMINFO'中再次看到答案 – 2013-04-09 23:47:31