Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2005, how to copy a Database Diagram to another server

Is there a way to copy a SQL Server Database Diagram to another server?

I found this and modified it sightly to copy only one diagram:

INSERT INTO dbB.dbo.sysdiagrams 
SELECT [name],[principal_id],[version],[definition]
FROM dbA.dbo.sysdiagrams
Where name = 'MyDiagramName'

But I need to copy it to another Server (Development to Production).

I don't want to create a linked server to do this. (Updated explanation) The reason behind that is that I want to include the diagram in a upgrade script. I made changes to the database to support a new version (new tables, etc) and I want the diagram be be part of the upgrade script. so it's best if i could put that in a SQL script. If a got a separated file to manually import afterward, it could do the job, but it not the best.

So i need to 'save' the diagram definition to a file somehow to restore it on the other server.

like image 565
DavRob60 Avatar asked Jul 22 '10 14:07

DavRob60


People also ask

How do I Export a diagram from SQL Server?

Right click on the database containing the diagrams. Click on All Tasks then on "Export data". The Import / Export option will be displayed, click Next. Define the source and then click Next.


1 Answers

Just found this solution.

In this article, There's the code to create the Stored Procedure that generate a SQL Server Script to recreate the diagrams. So you just save the output of the Stored Procedure in a .SQL file and run it on the other server.

The problem is to convert Varbinary To a String (Varchar) in Hex in order to be able use it in a insert/update query. But it's well explained in the link...

like image 92
DavRob60 Avatar answered Sep 23 '22 03:09

DavRob60