I use SQL Server 2012 and SQL Server 2008 R2.

I create a script from all object (tables / trigger / stored procedure / function ...) in my database.

I generated this script from SQL Server Management Studio.

I can recreate my database with this scrips on the other server.

But I miss all diagrams of my database after run my script for create another database.

Therefore, I need create backup script from all diagrams that exist in my database.

I need execute this script on the destination database for recreating all my diagrams.

I found this Link. but i need some thinks that create all script (Insert Command) automatically.

  • 1
    Why don't you just create a backup of the database? I don't know of any way to script the diagrams, because there may be diagrams there that you don't have access to (e.g. if you didn't create them and you are not db_owner). – Aaron Bertrand Oct 31 '13 at 15:46
  • because i do not need data. – Ardalan Shahgholi Nov 1 '13 at 0:16
  • this answer on SO I believe is a more complete script to go by for moving diagrams. – user507 Dec 27 '14 at 1:28

I write this query and this work.

USE DestinationDatabase

DELETE  sysDiagrams
WHERE   name IN ( SELECT    name
              FROM      SourceDatabase.dbo.sysDiagrams )


INSERT  sysDiagrams
    ( name ,
      principal_id ,
      diagram_id ,
      version ,
    SELECT  name ,
            principal_id ,
            diagram_id ,
            version ,
    FROM    SourceDatabase.dbo.sysDiagrams

  • 1
    This script worked perfectly for me. A large diagram got corrupted and I could restore it from a copy in test-environment: This script saved me a lot of time. – 7of1 May 1 '20 at 6:46

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.