我正在尝试创建多个表并收到不同的错误: 我在某些表上收到没有正确的括号错误,每个表只有1个主键。
CREATE TABLE GAMER
(
USERNAME VARCHAR(255) PRIMARY KEY ,
PASSWORD_password VARCHAR(255) ,
FIRSTNAME VARCHAR(255) ,
LASTNAME VARCHAR(255) ,
EMAIL VARCHAR(255)
);
CREATE TABLE CHARACTER_character
(
CHARACTER_NAME VARCHAR(150) PRIMARY KEY ,
LEVEL_level INT(150) ,
EXP_exp INT(1250) ,
HP INT(1250) ,
MP INT(1250) ,
STRENGTH INT(1250) ,
INTILLIGENCE INT(1250) ,
DEXTERITY INT(1250) ,
CLASS_class VARCHAR(150) ,
USERNAME VARCHAR(150) ,
CONSTRAINT username_fk FOREIGN KEY (USERNAME) REFERENCES GAMER
);
CREATE TABLE PVP_MATCH
(
MATCHID INT(15) PRIMARY KEY ,
WINNER_NAME VARCHAR(150),
LOSER_NAME VARCHAR(150) ,
KILL_TIME INT(2000) ,
KILL_SCORE INT(2000) ,
CONSTRAINT WINNER_NAME_fk FOREIGN KEY (WINNER_NAME) REFERENCES CHARACTER_character(CHARACTER_NAME) ,
CONSTRAINT LOSER_NAME_fk FOREIGN KEY (LOSER_NAME) REFERENCES CHARACTER_character(CHARACTER_NAME)
);
CREATE TABLE GUILD
(
GUILD_NAME VARCHAR(150)PRIMARY KEY ,
FOUNDING_TIME VARCHAR(1500) ,
STATUS VARCHAR(1500)
);
CREATE TABLE CHARACTER_GUILD
(
GUILD_NAME VARCHAR(1500) PRIMARY KEY ,
CHARACTER_NAME VARCHAR(1500) PRIMARY KEY ,
CONSTRAINT GUILD_NAME_fk FOREIGN KEY (GUILD_NAME) REFERENCES GUILD(GUILD_NAME) ,
CONSTRAINT CHARACTER_NAME_fk FOREIGN KEY (CHARACTER_NAME) REFERENCES CHARACTER_character(CHARACTER_NAME)
);
CREATE TABLE ITEM
(
ITEM_NAME VARCHAR(1500) PRIMARY KEY ,
VALUE_value INT(1500) ,
STATUS VARCHAR(1500) ,
TYPE_type INT(1500)
);
CREATE TABLE ARMOR
(
ITEM_NAME VARCHAR(1500) PRIMARY KEY ,
DEFENSE INT(1500) ,
TYPE_type INT(1500) ,
CONSTRAINT ITEM_NAME_fk FOREIGN KEY (ITEM_NAME) REFERENCES ITEM(ITEM_NAME)
);
CREATE TABLE ACCESSORY (
ITEM_NAME VARCHAR(1500) PRIMARY KEY ,
SPECIAL_EFFECTS VARCHAR(1500) ,
TYPE_type VARCHAR(1500) ,
CONSTRAINT ITEM_NAME_fk FOREIGN KEY (ITEM_NAME) REFERENCES ITEM(ITEM_NAME)
);
CREATE TABLE WEAPON (
ITEM_NAME VARCHAR(1500) PRIMARY KEY ,
SPEED INT(1500) ,
DPS INT(1500) ,
CONSTRAINT ITEM_NAME_fk FOREIGN KEY (ITEM_NAME) REFERENCES ITEM(ITEM_NAME)
);
CREATE TABLE CHARACTER_ITEM
(
CHARACTER_NAME VARCHAR(1500) PRIMARY KEY,
ITEM_NAME VARCHAR(1500) PRIMARY KEY,
CONSTRAINT ITEM_NAME_fk FOREIGN KEY (ITEM_NAME) REFERENCES ITEM(ITEM_NAME) ,
CONSTRAINT CHARACTER_NAME_fk FOREIGN KEY (CHARACTER_NAME) REFERENCES CHARACTER_character
);
CREATE TABLE SKILL
(
SKILL_ID INT(1500) PRIMARY KEY,
NAME_name VARCHAR(1500) ,
MPCOST INT(1500) ,
LEVEL_level INT(1500) ,
DESCRIPTION VARCHAR(1500)
);
CREATE TABLE CHARACTER_SKILL
(
CHARACTER_NAME VARCHAR(1500) PRIMARY KEY ,
SKILL_ID INT(1500) PRIMARY KEY,
CONSTRAINT CHARACTER_NAME_fk FOREIGN KEY CHARACTER_NAME REFERENCES CHARACTER_character(CHARACTER_NAME) ,
CONSTRAINT SKILL_ID_fk FOREIGN KEY SKILL_ID REFERENCES SKILL(SKILL_ID)
);
CREATE TABLE PREREQUISITE_SKILL
(
SKILL_ID INT(1500) PRIMARY KEY ,
PREREQUISITE_SKILL_ID VARCHAR(1500) PRIMARY KEY ,
CONSTRAINT SKILL_ID_fk FOREIGN KEY SKILL_ID REFERENCES SKILL(SKILL_ID) ,
CONSTRAINT PREREQUISITE_SKILL_ID_fk FOREIGN KEY (PREREQUISITE_SKILL_ID) REFERENCES SKILL(SKILL_ID)
);
我试过运行这么简单的事情:
CREATE TABLE GUILD
(
GUILD_NAME VARCHAR(150)PRIMARY KEY ,
FOUNDING_TIME VARCHAR(1500) ,
STATUS VARCHAR(1500)
);
但是我收到了没有正确的括号错误。格式似乎正确。
答案 0 :(得分:2)
几个错误:INT类型不接受任何宽度参数(数字可以做),复合主键需要声明为约束,并且有几个名称冲突。另外,在最后一个表中,PREREQUISITE_SKILL_ID
的数据类型被声明为VARCHAR(1500)
,但它看起来应该是INT
,因为它引用了在INT
中声明为SKILL
的字段。 CREATE TABLE GAMER
(
USERNAME VARCHAR(255) PRIMARY KEY ,
PASSWORD_password VARCHAR(255) ,
FIRSTNAME VARCHAR(255) ,
LASTNAME VARCHAR(255) ,
EMAIL VARCHAR(255)
);
CREATE TABLE CHARACTER_character
(
CHARACTER_NAME VARCHAR(150) PRIMARY KEY ,
LEVEL_level INT ,
EXP_exp INT ,
HP INT ,
MP INT ,
STRENGTH INT ,
INTILLIGENCE INT ,
DEXTERITY INT ,
CLASS_class VARCHAR(150) ,
USERNAME VARCHAR(150) ,
CONSTRAINT username_fk FOREIGN KEY (USERNAME) REFERENCES GAMER
);
CREATE TABLE PVP_MATCH
(
MATCHID INT PRIMARY KEY ,
WINNER_NAME VARCHAR(150),
LOSER_NAME VARCHAR(150) ,
KILL_TIME INT ,
KILL_SCORE INT ,
CONSTRAINT WINNER_NAME_fk FOREIGN KEY (WINNER_NAME) REFERENCES CHARACTER_character ,
CONSTRAINT LOSER_NAME_fk FOREIGN KEY (LOSER_NAME) REFERENCES CHARACTER_character
);
CREATE TABLE GUILD
(
GUILD_NAME VARCHAR(150)PRIMARY KEY ,
FOUNDING_TIME VARCHAR(1500) ,
STATUS VARCHAR(1500)
);
CREATE TABLE CHARACTER_GUILD
(
GUILD_NAME VARCHAR(1500),
CHARACTER_NAME VARCHAR(1500),
CONSTRAINT CHARACTER_GUILD_PK PRIMARY KEY (GUILD_NAME, CHARACTER_NAME),
CONSTRAINT GUILD_NAME_fk3 FOREIGN KEY (GUILD_NAME) REFERENCES GUILD ,
CONSTRAINT CHARACTER_NAME_fk4 FOREIGN KEY (CHARACTER_NAME) REFERENCES CHARACTER_character
);
CREATE TABLE ITEM
(
ITEM_NAME VARCHAR(1500) PRIMARY KEY ,
VALUE_value INT ,
STATUS VARCHAR(1500) ,
TYPE_type INT
);
CREATE TABLE ARMOR
(
ITEM_NAME VARCHAR(1500) PRIMARY KEY ,
DEFENSE INT ,
TYPE_type INT ,
CONSTRAINT ITEM_NAME_fk FOREIGN KEY (ITEM_NAME) REFERENCES ITEM
);
CREATE TABLE ACCESSORY (
ITEM_NAME VARCHAR(1500) PRIMARY KEY ,
SPECIAL_EFFECTS VARCHAR(1500) ,
TYPE_type VARCHAR(1500) ,
CONSTRAINT ITEM_NAME_fk4 FOREIGN KEY (ITEM_NAME) REFERENCES ITEM
);
CREATE TABLE WEAPON (
ITEM_NAME VARCHAR(1500) PRIMARY KEY ,
SPEED INT ,
DPS INT ,
CONSTRAINT ITEM_NAME_fk2 FOREIGN KEY (ITEM_NAME) REFERENCES ITEM
);
CREATE TABLE CHARACTER_ITEM
(
CHARACTER_NAME VARCHAR(1500),
ITEM_NAME VARCHAR(1500),
CONSTRAINT CHARACTER_ITEM_PK PRIMARY KEY (CHARACTER_NAME, ITEM_NAME),
CONSTRAINT ITEM_NAME_fk3 FOREIGN KEY (ITEM_NAME) REFERENCES ITEM ,
CONSTRAINT CHARACTER_NAME_fk FOREIGN KEY (CHARACTER_NAME) REFERENCES CHARACTER_character
);
CREATE TABLE SKILL
(
SKILL_ID INT PRIMARY KEY,
NAME_name VARCHAR(1500) ,
MPCOST INT ,
LEVEL_level INT ,
DESCRIPTION VARCHAR(1500)
);
CREATE TABLE CHARACTER_SKILL
(
CHARACTER_NAME VARCHAR(1500),
SKILL_ID INT,
CONSTRAINT CHARACTER_SKILL_PK PRIMARY KEY (CHARACTER_NAME, SKILL_ID),
CONSTRAINT CHARACTER_NAME_fk34 FOREIGN KEY (CHARACTER_NAME) REFERENCES CHARACTER_character ,
CONSTRAINT SKILL_ID_f1k FOREIGN KEY (SKILL_ID) REFERENCES SKILL
);
CREATE TABLE PREREQUISITE_SKILL
(
SKILL_ID INT,
PREREQUISITE_SKILL_ID INT,
CONSTRAINT PREREQUISITE_SKILL_PK PRIMARY KEY (SKILL_ID, PREREQUISITE_SKILL_ID),
CONSTRAINT SKILL_ID_fk2 FOREIGN KEY (SKILL_ID) REFERENCES SKILL,
CONSTRAINT PREREQUISITE_SKILL_ID_fk FOREIGN KEY (PREREQUISITE_SKILL_ID) REFERENCES SKILL(SKILL_ID)
);
表。
为您修复此问题:请参阅示例SQL Fiddle以获取证明(使用Oracle 11G R2)。
{{1}}
我没有考虑解决约束名称冲突,只是添加了随机数。你肯定可以改进它们。