3

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.

4

Although this question is a year old, if anyone stumble over this, I've posted a solution to make that possible here:

http://www.codeproject.com/Messages/4914888/Search-through-the-binary-for-all-contained-texts.aspx

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.

2

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.

  • I have seen dbo.sysdiagrams but isn't there documentation on how deserialize the binary field? This information is important to replicate the schema diagram on (for instance) Visio. It's strange that binary isn't documented. – usergis Sep 27 '13 at 6:54
  • 1
    @usergis: I can't find anything on Google, and I doubt they would have done so for something like this. The format as it sits would be subject to change between versions anyway. – Jon Seigel Sep 27 '13 at 13:16
-1

In SQL Server Management Studio:

USE YourDBName
GO 
SELECT * FROM sys.Tables
GO

Or in MySQL:

use YourDBName;
show tables;
  • 5
    OP wants only the tables included in a SQL Server diagram. Not the complete list of tables in the database. – squillman Sep 24 '13 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.