I recently built a SQL Server 2016 production database from a development database. Unfortunately, the database diagrams that had been created in the development database were lost. Since the new and the old database both contain the same tables and schema objects, I decided to copy database diagrams from one database to another.
Sysdiagrams is a table that is used to store diagrams definitions for the database. I enabled it on the new database and inserted the data from the old sysdiagrams table into the new sysdiagrams table. Even thought sysdiagrams table is located under system tables, it is not considered as system table by SQL Server. SQL Server Management Studio(SSMS) creates them to store the diagrams definitions. It also categorizes as a system tables.
Since its considered as user tables you can display them with below query:
SELECT *
FROM sys.tables t
WHERE OBJECTPROPERTY(t.object_id,’IsUserTable’) = 1
Or you can view it in SSMS:
And here is the script I used to copy sysdiagrams:
USE [DestinationDatabase]
GO
SET IDENTITY_INSERT sysDiagrams ON
GO
INSERT sysDiagrams (name,
principal_id,
diagram_id,
version,
definition)
SELECT name,
principal_id,
diagram_id,
version,
definition
FROM SourceDatabase.dbo.sysDiagrams
GO
SET IDENTITY_INSERT sysDiagrams OFF
GO