我不擅長編寫創建腳本。並且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.
我在做什麼錯?
這個問題包含太多的錯誤需要一次處理。我建議通過逐個執行它們並試圖單獨處理每個錯誤來分別理解每個語句。例如 - 你的腳本中的第一個錯誤是'table或view'不存在'類型,所以你可以理解它們的原因是試圖刪除一個不存在的表。在你篩選出所有成功的陳述並嘗試自己解決一些錯誤之後,你應該爲單個陳述提出問題,這是錯誤的。 –
在這種情況下,請忽略drop語句中的錯誤,因爲創建失敗,所以它們是預期的。創作中的一些錯誤是因爲較早的失敗,所以從第一個非丟棄錯誤開始,並找出結果。哪個是ORA-02270創建Stream的;這是不言而喻的。 (提示:該表不應該有玩家名*存儲)。 –
呃,好吧,那不是第一個,在所有錯誤的未格式化轉儲中很難看到。查看您創建表的順序,以及它們引用的其他表。當您創建Accountsite時,Player是否存在?這也有同樣的問題存儲玩家的名字。 –