I need to get a list of the tables contained in a diagram in SQL Server. How can I do it using an SQL script?
I don't need a list of tables in the database, but the list of tables contained in a diagram of the database in SQL Server 2008r2/2012.
Although this question is a year old, if anyone stumble over this, I've posted a solution to make that possible here:
The trick is to extract all ASCII characters in the diagram binary, you'll see that all table names are in there as simple text. That seems to be the reason why a diagram is also destroyed if you rename a table with a script - because it doesn't use a table ID to identify the table but the table name. If it's no longer there, the diagram is not usable anymore.
With this method you can identify which diagrams contains a specific table.
Unfortunately, there's no way to do this, unless you can figure out how to deserialize the binary field that represents the diagram.
Database Diagrams are stored in
dbo.sysdiagrams (inside your user database) if you want to give it a shot.
In SQL Server Management Studio:
USE YourDBName GO SELECT * FROM sys.Tables GO
Or in MySQL:
use YourDBName; show tables;