Hey I'm pretty new to databases and I want to create a diagram of the db I'm using with dbdiagram.io so that I can't understand the relationships better. What sort of script/file am I supposed to use to import the schema from sql server? I'm currently using azure data studio to query the database. I would prefer not to have to write out all the tables by hand.
1 Answers
Based on the docs and the DBML language, you need to generate a DBML script in the following format from your RDBMS of choice - in this case, SQL Server:
Table Users {
UserID integer [pk]
}
Table Posts {
PostID integer [pk]
UserID integer [ref: > Users.UserID] // many-to-one
}
Note that this DBML output is not intended to run on your RDBMS, SQL Server or otherwise - those platforms don't understand DBML. It is an example of output you need to generate from your RDBMS that you can paste directly into the left editor pane on dbdiagram.io, as demonstrated here.
This more complicated example - which uses DBML to build a diagram from SQL Server based on a subset of the tables in Stack Exchange Data Explorer (and which I described here) - took about 40 seconds to create.
You can build this syntax from a set of tables without having to hard-code each one using catalog views like sys.tables
and sys.columns
, but there are a lot of little things that you'll have to do to make it compatible with this web site, and that will be a project all its own. Basically, nothing in SQL Server exists to generate nice, tidy DBML for you.
If you don't want to use DBML but would rather use the Import
feature on the web site, then you can generate traditional DDL scripts instead - from SQL Server, you can do this by right-clicking the database in SSMS / Object Explorer and using Script Database as
> CREATE To
. Azure Data Studio doesn't yet have this functionality, but you can use an extension.

- 272,866
- 37
- 466
- 490
-
This answer is a bit rude and factually incorrect. If you attempt to import the script in Postgres exactly as written above, you get an error in dbdiagramio: 'Expected "ALTER","COMMENT","CREATE"....' – Rudy Stricklan Sep 25 '22 at 20:55
-
@Aaron-- which DBMS do these statement work for, then? – Rudy Stricklan Sep 26 '22 at 23:18