创建表时出错(ORA - 00972)

时间:2017-12-14 05:43:51

标签: sql oracle oracle12c

以下是我成功创建的表格:

CREATE TABLE Olympic_Game 
(
 og_id NUMBER(3) PRIMARY KEY,
 og_type_id NUMBER(3) NOT NULL,
 og_year NUMBER(4) NOT NULL,
 og_website VARCHAR(150),
 og_cancel VARCHAR(1) NOT NULL,
 country_id NUMBER(3) NOT NULL,
 CONSTRAINT check_og_id CHECK (og_id > 0),
 CONSTRAINT check_og_cancel CHECK (og_cancel IN ('Y','N')),
 CONSTRAINT check_og_year_og_type UNIQUE (og_type_id, og_year),
 CONSTRAINT fk_og_type_id FOREIGN KEY(og_type_id) REFERENCES OG_Type(og_type_id),
 CONSTRAINT fk_country_id FOREIGN KEY(country_id) REFERENCES Country(country_id)
);

CREATE TABLE Sport 
(
 sport_id NUMBER(3) PRIMARY KEY,
 sport_title VARCHAR(100) UNIQUE NOT NULL,
 CONSTRAINT check_sport_id CHECK (sport_id > 0)
);

然后我尝试创建另一个名为Event

的表
CREATE TABLE Event 
(
 event_id NUMBER(6) PRIMARY KEY,
 sport_id NUMBER(3) NOT NULL,
 og_id NUMBER(3) NOT NULL,
 event_title VARCHAR(100) NOT NULL,
 event_team  VARCHAR(1) NOT NULL,
 no_per_team  NUMBER(2) NOT NULL,
 event_gender VARCHAR(1) NOT NULL,
 CONSTRAINT check_event_id CHECK (event_id > 0),
 CONSTRAINT check_event_title_sport_id_og_id_event_team_event_gender UNIQUE (event_title, sport_id, og_id, event_team, event_gender),
 CONSTRAINT check_event_team CHECK (event_team IN ('Y','N')),
 CONSTRAINT check_event_team_no_per_team CHECK ((event_team='N' AND no_per_team=1) OR (event_team='Y' AND no_per_team>1)),
 CONSTRAINT check_event_gender CHECK (event_gender IN ('M','F')),
 CONSTRAINT fk_sport_id FOREIGN KEY(sport_id) REFERENCES Sport(sport_id),
 CONSTRAINT fk_og_id FOREIGN KEY(og_id) REFERENCES Olympic_Game(og_id)
);

但是我收到以下错误:

Error report -
SQL Error: ORA-00972: identifier is too long
00972. 00000 -  "identifier is too long"
*Cause:    An identifier with more than 30 characters was specified.
*Action:   Specify at most 30 characters.

我可能在哪里出错?

2 个答案:

答案 0 :(得分:3)

错误非常清楚地表明,约束的check_event_title_sport_id_og_id_event_team_event_gender名称似乎太长了。

您需要将其更改为长度不超过30个字符的短文。

Btw约束名称的长度是56个字符......

答案 1 :(得分:0)

系统表中的数据库保存标识符名称,因此您不能排在长名称之前。

相关问题