我使用BIT DEFAULT 0,
作爲布爾不知道它的權利是否如此。那麼,問題是我不能創建任何表,因爲在FK有問題,不明白爲什麼?我還添加了ERD圖像以獲得更好的視野。SQL DB創建錯誤
也許有人會/可以很好,並向我解釋,ty!
也許有人知道任何好的程序或在線沙箱的turtnind ERD的MSSQL代碼或MySQL代碼?如果免費使用它將會很好。提前致謝!
CREATE DataBase LO;
GO
USE LO;
CREATE TABLE Weapon
(
ClassWeapon CHAR(50) NULL,
Level INT NULL,
MinDmg INT NULL,
MaxDmg INT NULL,
AtkSpeed NUMERIC(3,2) NULL,
PerSecondDmg NUMERIC(6,2) NULL,
PlayerLevel INT NULL,
SkillLevel INT NULL,
Image BIT DEFAULT 0 NULL,
Name CHAR(100) NULL,
Weapons CHAR(50) NOT NULL,
Monsters CHAR(50) NULL,
PRIMARY KEY (Weapons),
FOREIGN KEY (Monsters) REFERENCES Monster(Monsters)
);
CREATE TABLE Armor
(
ClassArmor CHAR(50) NULL,
Name CHAR(100) NULL,
Level INT NULL,
Defense INT NULL,
Image BIT DEFAULT 0 NULL,
Armors CHAR(50) NOT NULL,
Monsters CHAR(50) NULL,
PRIMARY KEY (Armors),
FOREIGN KEY (Monsters) REFERENCES Monster(Monsters)
);
CREATE TABLE Menu
(
Weapons CHAR(50) NULL,
Armors CHAR(50) NULL,
Monsters CHAR(50) NULL,
FOREIGN KEY (Weapons) REFERENCES Weapon(Weapons),
FOREIGN KEY (Armors) REFERENCES Armor(Armors),
FOREIGN KEY (Monsters) REFERENCES Monster(Monsters)
);
CREATE TABLE Monster
(
Name CHAR(100) NULL,
Level INT NULL,
MinHealth INT NULL,
MaxHealth INT NULL,
MinDmg INT NULL,
MaxDmg INT NULL,
AtkSpeed NUMERIC(3,2) NULL,
Location CHAR(100) NULL,
Monsters CHAR(50) NOT NULL,
DropItems CHAR(100) NULL,
Image BIT DEFAULT 0 NULL,
PRIMARY KEY (Monsters),
FOREIGN KEY (DropItems) REFERENCES Items(DropItems)
);
CREATE TABLE Items
(
DropItems CHAR(100) NOT NULL,
Weapons CHAR(50) NULL,
Armors CHAR(50) NULL,
PRIMARY KEY (DropItems),
FOREIGN KEY (Weapons) REFERENCES Weapon(Weapons),
FOREIGN KEY (Armors) REFERENCES Armor(Armors)
);
1)創建表2)使用'ALTER TABLE'語法創建FK。在SQL中沒有前向聲明。例如武器會引用Monster表(不存在)。 – lad2025