-1

我正在运行这两个命令来创建新表,但是第二个创建表命令一直给我错误。

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

2 回答 2

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

于 2013-04-09T23:44:22.137 回答
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)
);
于 2013-04-09T23:39:17.870 回答