我不擅长编写创建脚本。并且SQL Developer错误消息对我没有帮助。我正在寻找帮助我找出错误的人,因为我不能单独做这件事。
这是我的代码:
/*Drops */
DROP TABLE Accountsite CASCADE CONSTRAINTS;
DROP TABLE Player CASCADE CONSTRAINTS;
DROP TABLE Stream CASCADE CONSTRAINTS;
DROP TABLE Server CASCADE CONSTRAINTS;
DROP TABLE Activegame CASCADE CONSTRAINTS;
DROP TABLE Livegame CASCADE CONSTRAINTS;
DROP TABLE Toplist CASCADE CONSTRAINTS;
DROP TABLE Champion CASCADE CONSTRAINTS;
DROP TABLE Skin CASCADE CONSTRAINTS;
DROP TABLE Sale CASCADE CONSTRAINTS;
DROP TABLE PlayerServer CASCADE CONSTRAINTS;
DROP TABLE ActiveServer CASCADE CONSTRAINTS;
/*Creates */
CREATE TABLE Accountsite(
AccountID NUMBER PRIMARY KEY NOT NULL,
PasswordAcc VARCHAR(20) NULL,
Email VARCHAR(20) NULL,
Playername VARCHAR(20) NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername));
CREATE TABLE Player(
PlayerID NUMBER PRIMARY KEY,
Mostplayed VARCHAR(20) NOT NULL,
RankID NUMBER(10) NOT NULL,
Playername VARCHAR(20) NOT NULL);
CREATE TABLE Stream(
StreamID NUMBER PRIMARY KEY,
StreamAdress VARCHAR(20) NOT NULL,
Playername VARCHAR(20) NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername));
CREATE TABLE Server(
ServerID NUMBER PRIMARY KEY,
Servername VARCHAR(20));
CREATE TABLE Activegame(
GameID NUMBER PRIMARY KEY);
CREATE TABLE Livegame(
SpectateID NUMBER PRIMARY KEY);
CREATE TABLE Toplist(
ToplistID NUMBER PRIMARY KEY,
ToplistFunction VARCHAR(20) NOT NULL,
Playername VARCHAR(20) NOT NULL,
Championname VARCHAR(20) NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername),
FOREIGN KEY(Champion) REFERENCES Champion (Champion));
CREATE TABLE Champion(
ChampionID NUMBER PRIMARY KEY,
Championname VARCHAR(20) NOT NULL,
Championskill1 VARCHAR(20) NOT NULL,
Championskill2 VARCHAR(20) NOT NULL,
Championskill3 VARCHAR(20) NOT NULL,
Championskill4 VARCHAR(20) NOT NULL,
Championcost NUMBER(10) DEFAULT(6300),
SkinID NUMBER(10) NOT NULL,
SaleID NUMBER(10) NOT NULL,
FOREIGN KEY(SkinID) REFERENCES Skin (SkinID),
FOREIGN KEY(SaleID) REFERENCES Sale (SaleID));
CREATE TABLE Skin(
SkinID NUMBER PRIMARY KEY,
Skinname VARCHAR(20) NOT NULL,
Skincost NUMBER(10) NOT NULL);
CREATE TABLE Sale(
SaleID NUMBER PRIMARY KEY);
CREATE TABLE PlayerServer(
Playername VARCHAR(20) NOT NULL,
ServerIDPlayer NUMBER NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername),
FOREIGN KEY(ServerIDPlayer) REFERENCES Server (ServerID),
Constraint PlayerserverID PRIMARY KEY (Playername, ServerIDPlayer));
CREATE TABLE ActiveServer(
GameIDServer NUMBER NOT NULL,
ServerIDGame NUMBER NOT NULL,
FOREIGN KEY(GameIDServer) REFERENCES Acrivegame (GameID),
FOREIGN KEY(ServerIDGame) REFERENCES Server (ServerID),
Constraint ActiveserverID PRIMARY KEY (GameIDServer, ServerIDGame));
commit;
错误如下:
Error starting at line : 2 in command -
DROP TABLE Accountsite CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table PLAYER dropped.
Error starting at line : 4 in command -
DROP TABLE Stream CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table SERVER dropped.
Table ACTIVEGAME dropped.
Table LIVEGAME dropped.
Error starting at line : 8 in command -
DROP TABLE Toplist CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error starting at line : 9 in command -
DROP TABLE Champion CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table SKIN dropped.
Table SALE dropped.
Error starting at line : 12 in command -
DROP TABLE PlayerServer CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error starting at line : 13 in command -
DROP TABLE ActiveServer CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error starting at line : 16 in command -
CREATE TABLE Accountsite(
AccountID NUMBER PRIMARY KEY NOT NULL,
PasswordAcc VARCHAR(20) NULL,
Email VARCHAR(20) NULL,
Playername VARCHAR(20) NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername))
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table PLAYER created.
Error starting at line : 29 in command -
CREATE TABLE Stream(
StreamID NUMBER PRIMARY KEY,
StreamAdress VARCHAR(20) NOT NULL,
Playername VARCHAR(20) NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername))
Error report -
SQL Error: ORA-02270: Geen overeenkomende unieke of primaire sleutel voor deze kolomlijst.
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view
Table SERVER created.
Table ACTIVEGAME created.
Table LIVEGAME created.
Error starting at line : 45 in command -
CREATE TABLE Toplist(
ToplistID NUMBER PRIMARY KEY,
ToplistFunction VARCHAR(20) NOT NULL,
Playername VARCHAR(20) NOT NULL,
Championname VARCHAR(20) NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername),
FOREIGN KEY(Champion) REFERENCES Champion (Champion))
Error report -
SQL Error: ORA-00904: "CHAMPION": ongeldige ID
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error starting at line : 53 in command -
CREATE TABLE Champion(
ChampionID NUMBER PRIMARY KEY,
Championname VARCHAR(20) NOT NULL,
Championskill1 VARCHAR(20) NOT NULL,
Championskill2 VARCHAR(20) NOT NULL,
Championskill3 VARCHAR(20) NOT NULL,
Championskill4 VARCHAR(20) NOT NULL,
Championcost NUMBER(10) DEFAULT(6300),
SkinID NUMBER(10) NOT NULL,
SaleID NUMBER(10) NOT NULL,
FOREIGN KEY(SkinID) REFERENCES Skin (SkinID),
FOREIGN KEY(SaleID) REFERENCES Sale (SaleID))
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table SKIN created.
Table SALE created.
Error starting at line : 74 in command -
CREATE TABLE PlayerServer(
Playername VARCHAR(20) NOT NULL,
ServerIDPlayer NUMBER NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername),
FOREIGN KEY(ServerIDPlayer) REFERENCES Server (ServerID),
Constraint PlayerserverID PRIMARY KEY (Playername, ServerIDPlayer))
Error report -
SQL Error: ORA-02270: Geen overeenkomende unieke of primaire sleutel voor deze kolomlijst.
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view
Error starting at line : 81 in command -
CREATE TABLE ActiveServer(
GameIDServer NUMBER NOT NULL,
ServerIDGame NUMBER NOT NULL,
FOREIGN KEY(GameIDServer) REFERENCES Acrivegame (GameID),
FOREIGN KEY(ServerIDGame) REFERENCES Server (ServerID),
Constraint ActiveserverID PRIMARY KEY (GameIDServer, ServerIDGame))
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Commit complete.
我做错了什么?
答案 0 :(得分:0)
您的脚本存在多个问题。基本上,当您包含外键约束时,它们必须指向一个已存在的表中的唯一列(必须在引用表之前创建)。
尝试删除表时的错误
你基本上得到ORA-00942
,因为你的表不存在,所以不能删除它。作为一种解决方法,您可以捕获该异常。它已被描述为in this answer。
尝试创建表时的错误
本主题中有几个问题。第一个是执行表Accountsite
的create语句时。您还在此处获得ORA-00942
,因为您尝试在外键约束中引用的表Player
不存在。您需要在Accountsite
之前创建它,以便它可以引用存在的内容。
创建表Stream
时发生下一个错误。它是ORA-02270
。您不能从另一个表中引用不唯一的列。您需要在表Playername
中使Player
列唯一。请注意,当您使用Accountsite
表修复第一个错误时,此表与Stream
的错误相同,因为您尝试引用在两个create table语句中都不唯一的列(所以你还需要修复第二个错误,它会没有错误)。
现在是Toplist
表。您的Champion
表格中没有Champion
列。你可能意味着Championname
。在这种情况下,还需要在Champion
表之前创建Toplist
表,因为您无法为不存在的表创建外键约束。您还需要在Championname
表格中声明Champion
列的唯一性(与表格Playername
中的Player
一样)。
在Champion
中,您引用了Sale
和Skin
表 - 它们都需要在Champion
表之前创建(请参阅上面的说明)。
至于PlayerServer
,当您在Player(Playername)
上创建唯一约束时,错误将自行解决。
在ActiveServer
中,您引用了"Acrivegame"
的错字,我认为应该是Activegame
。