SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Generate scripts for SQL Server Management Studio diagrams

By Jonas Gunnarsson,

The procedure generates an import script for SQL Server Management Studio diagrams.
Easy to use, takes one diagram name and an optional parameter, if is first diagram to script.

List the database diagram(s) for current database:

select * from sysdiagrams;

The script is based on several other scripts, see the References section.

Example of usage:

execute tool.ScriptDiagram 'First', 1;
execute tool.ScriptDiagram 'Second', 0;
execute tool.ScriptDiagram 'Third', 0;

Objects required to use database diagrams is added for owner, when clicking on Database Diagrams in SSMS.

Further reading



  • 1.3 2017-03-22 Fixed links and use only tab in code
  • 1.4 2017-10-23 cleanup procedure
  • 1.5 2018-05-25 cleanup procedure, no dates

Total article views: 1413 | Views in the last 30 days: 27
Related Articles

Database diagrams

Database diagrams


Export diagrams

Export diagrams in current database to an import script.


Database Modeling and Diagrams with SQL Server 2008

How to use Database Diagram tool in SQL SERVER.


Database Diagram

Facing Problem with Database Diagram


Transferring Database Diagrams

HOw can one transfer the database diagrams from one box to another