We discussed in one of the previous articles called “How to store a SQL Server database diagram into a file and share it with others?” we can store database diagrams in files and share the files with others. In this article I’m describing very fast and easy ways to make a copy of existing database diagrams into another database. The possible scenarios are:
1. We want to create a copy of database diagrams into another database in the same SQL Server instance
2. We want to make a copy of database diagrams in another instance of SQL server
In both cases we need to have write access permission on the destination database.
Migrating database diagrams between two databases in the same instance
We just need to run the following T-SQL script:
use DESTINATIONDB
IF OBJECT_ID(N’dbo.sysdiagrams’) IS NULL
begin
CREATE TABLE dbo.sysdiagrams
(
name sysname NOT NULL,
principal_id int NOT NULL,
diagram_id int PRIMARY KEY IDENTITY,
version int,
definition varbinary(max)
CONSTRAINT UK_principal_name UNIQUE
(
principal_id,
name
)
)
EXEC SYS.SP_MS_MARKSYSTEMOBJECT ‘sysdiagrams’ —Creating a system object
End
Insert into sysdiagrams (name,principal_id,version,definition)
select name,principal_id,version,definition from SOURCEDB.dbo.sysdiagrams
The above solution works even if you did not install diagram support and you’ll have the copy of diagrams in place immediately after installing diagram support. To install database diagram support:
1. Expand the destination database
2. Right click on “Database diagrams”
3. Click “Install Diagram Support”
Continue reading “How to copy or migrate database diagrams into another database”