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.
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...
First : Create one Link Server From Source Server
inside Destination Server
.
For create Link Server
use this Link
Second : Use This
USE DestinationDatabase
DELETE sysDiagrams
WHERE name IN ( SELECT name
FROM <LinkServerName>.SourceDatabase.dbo.sysDiagrams )
SET IDENTITY_INSERT sysDiagrams ON
INSERT sysDiagrams
( name ,
principal_id ,
diagram_id ,
version ,
definition
)
SELECT name ,
principal_id ,
diagram_id ,
version ,
definition
FROM <LinkServerName>.SourceDatabase.dbo.sysDiagrams
SET IDENTITY_INSERT sysDiagrams OFF
This tutorial/example will explain it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.