Cannot create database diagram in SQL Server

zaq34kh6  于 12个月前  发布在  SQL Server
关注(0)|答案(1)|浏览(167)

I'm trying to create my first database and see its diagram. I'm using Microsoft SQL Server 2019 and I think I managed to create the database itself, but I am having trouble creating the diagram. This is exactly what I did:

I opened Microsoft SQL Server Management Studio , hit File , then New and then Query with Current Connection . I entered the following code to create a dummy database, just so I can visualize the diagram.

CREATE DATABASE CarDatabase;

CREATE TABLE Car(
    CarID INT PRIMARY KEY,
    CarName VARCHAR(255)
);

INSERT INTO Car(CarID, CarName)
VALUES(1, 'Mercedes');
INSERT INTO Car(CarID, CarName)
VALUES(2, 'BMW');
INSERT INTO Car(CarID, CarName)
VALUES(3, 'Porche');

SELECT * FROM Car;

CREATE TABLE Engines(
    EngineID INT PRIMARY KEY,
    EngineName VARCHAR(255),
    CarID INT FOREIGN KEY REFERENCES Car(CarID)
);

INSERT INTO Engines(EngineID, EngineName, CarID)
VALUES(1, 'Maybach S 400 4MATIC', 1);

SELECT * FROM Engines;

The above selects seemed to work just fine, so I think the code is ok. After a few searches on the internet I found out about what I need to do to generate that diagram, so that's what I did. On the left-hand side, in the Object Explorer , I expanded the Databases file and then I could see my database 'CarDatabase'. After I expanded this, I could see a file 'Database Diagrams'. I right clicked on it and installed the necessary support for database diagrams. Now I right click again and hit New Database Diagram . A window pops up. Here, I should see my tables ( Car and Engines ) and then I would select which ones I want in the diagram and then I would have these tables created in a diagram. The problem is that after clicking on 'New Database Diagram' none of my tables are shown in this window. I have nothing to select. I saw nothing about this in the tutorials I watched on the internet. I am for sure missing something, but I have no idea what. I couldn't find anything about it. I tried saving, closing the studio and then opening it again and it didn't work. I refreshed the cache ( Edit -> IntelliSense -> Refresh Local Cache ) and still nothing. I tried creating other databases (multiple times) hoping it would get solved, but still this issue persists.

What I am expecting to get is a diagram like the following:

ugmeyewa

ugmeyewa1#

You may click "refesh" in the add table window and see if it shows you tables to select. This is a workaround and not a solution.

相关问题