SQL 管理工作室 - 数据库关系图不显示创建的每个表



所以我创建了一个看起来像这样的数据库。

CREATE TABLE Budova
(
BudovaID int primary key not null,
BytyPocet int not null,
);
CREATE TABLE Skupina
(
SkupinaID int primary key not null,
NajemniciPocet int not null,
BytID int not null,
FOREIGN KEY (BytID) REFERENCES Byt(BytID) ON DELETE CASCADE,
);
CREATE TABLE Najemnici
(
NajemnikID int primary key not null,
Jmeno varchar(255) null,
Prijmeni varchar(255) null, 
Vek int null,
SkupinaID int not null,
BytID int not null,
CenaEnergii int not null,
FOREIGN KEY (BytID) REFERENCES Byt(BytID),
FOREIGN KEY (SkupinaID) REFERENCES Skupina(SkupinaID) 
);
CREATE TABLE Byt
(
BytID int primary key not null,
BudovaID int not null,
OpravaID int not null,
FOREIGN KEY (BudovaID) REFERENCES Budova(BudovaID) ON DELETE CASCADE,
FOREIGN KEY (OpravaID) REFERENCES Opravy(OpravaID) ON DELETE CASCADE
);
CREATE TABLE Vydaje
(
BytID int not null,
Voda int not null,
Elektrina int not null,
Plyn int not null,
Zaloha int not null,
Celkem int not null,
CelkemEura int not null
FOREIGN KEY (BytID) REFERENCES Byt(BytID)
);
CREATE TABLE Opravy 
(
OpravaID int primary key not null,
OpravaTyp varchar(255) not null,
OpravaCena int not null,
);

我在数据库中基本上有 6 个表,但是当我尝试创建数据库图表时,它并没有显示每个表。 如您所见,它仅显示其中的 5 个。

最后,它看起来像那样。

我试图更改引用,但它实际上已经下地狱了。你知道,我应该怎么做才能让它工作吗?

你的语句上有很多错误,不管你使用哪个dbms。

尝试按发布顺序创建此查询,否则外键将不起作用

CREATE TABLE Budova
(
BudovaID int primary key not null,
BytyPocet int not null
);
CREATE TABLE Opravy 
(
OpravaID int primary key not null,
OpravaTyp varchar(255) not null,
OpravaCena int not null
);
CREATE TABLE Byt
(
BytID int primary key not null,
BudovaID int not null,
OpravaID int not null,
FOREIGN KEY (BudovaID) REFERENCES Budova(BudovaID) ON DELETE CASCADE,
FOREIGN KEY (OpravaID) REFERENCES Opravy(OpravaID) ON DELETE CASCADE
);
CREATE TABLE Skupina
(
SkupinaID int primary key not null,
NajemniciPocet int not null,
BytID int not null,
FOREIGN KEY (BytID) REFERENCES Byt(BytID) ON DELETE CASCADE
);
CREATE TABLE Najemnici
(
NajemnikID int primary key not null,
Jmeno varchar(255) null,
Prijmeni varchar(255) null, 
Vek int null,
SkupinaID int not null,
BytID int not null,
CenaEnergii int not null,
FOREIGN KEY (BytID) REFERENCES Byt(BytID),
FOREIGN KEY (SkupinaID) REFERENCES Skupina(SkupinaID) 
);

CREATE TABLE Vydaje
(
BytID int not null,
Voda int not null,
Elektrina int not null,
Plyn int not null,
Zaloha int not null,
Celkem int not null,
CelkemEura int not null,
FOREIGN KEY (BytID) REFERENCES Byt(BytID)
);

最新更新