How to export a SQL Server 2008 Database Diagram to another DB?
diagram, sql-server
Solution
@Ash I was having the same problem. Here's what we did to get around it...
It seems that System Diagrams are stored within the "sysdiagrams" table. So the first thing you need to do is determine the diagram_id of the Diagram you wish to copy. Run the following query to list them all. ** Note you need to replace "SourceDB" with the name of your database.
-- List all database diagrams
SELECT * FROM [SourceDB].[dbo].sysdiagrams
Then you can use INSERT to duplicate the diagram from one database to another as follows. ** Note again replace "SourceDB" with the name of the Database containing the existing diagram and "DestinationDB" with the name of the Database you wish to copy to. Also @SourceDiagramId should be set to the id retrieved above.
-- Insert a particular database diagram
DECLARE @SourceDiagramId int = 1
INSERT INTO [DestinationDB].[dbo].sysdiagrams
SELECT [name],diagram_id , version,definition from [SourceDB].[dbo].sysdiagrams
WHERE diagram_id = @SourceDiagramId
Then you need to set the "principal_id" to 1 manually.
-- Update the principal id (no idea why, but it set the owner as some asp_net user
UPDATE [DestinationDB].[dbo].sysdiagrams
SET principal_id = 1
This worked for us it seems pretty hacky especially since the Diagram is stored entirely in a single binary field "definition".
Answer comes from: http://www.dotnetspider.com/resources/21180-Copy-or-move-database-digram-from-for.aspx
Problem
I use the handy Database Diagramming tool in SQL Server 2008 for creating and managing relationships. I have exported the sourceDB to the destinationDB but the diagram doesn't come across. I am looking around trying to figure out how to export just the diagram I have in one database to another... This online KB article fails since `select * from dtproperties` doesn't exist anymore.