Search code examples
sql-serverssmsdatabase-diagramming

SQL - Export Database Diagram - SSMS 17


I am trying to export 3 database (DB) diagrams from one DB to another using SSMS 17. I have tried the solution suggested here:

How to export a SQL Server 2008 Database Diagram to another DB?

This solution is also recommended in several other websites I have found so far, to copy the content of the table "sysdiagrams" from the source DB to the destination DB (3 rows in my case).

After doing this I can confirm that both "sysdiagrams" tables have the same content and the diagrams are imported in the destination DB. Nevertheless in each imported diagram I see only the tables but not the relationships. What I find strange is that the relationships are shortly visible while the tables in the diagram are being loaded. After all tables are loaded they just dissappear.

Does anyone know what the issue could be? It is my understanding, that this solution is successful for early versions of SSMS.

Any help is highly appreciated :) !


Solution

  • Check that the relations (Foreign Key constraints) actually exist in the target database, because if they don't then the diagram editor will behave exactly as you describe: initially it will draw all lines, then it starts looking for each FK relation that each line represents, and it will one by one remove lines for which relations are not found.

    To clarify, you can create FK relations using the Diagram Editor by drawing a line between to tables (the editor then creates both a line in the diagram and the actual FK constraint). But with a 'copy diagram' action like yours, you copy only the line data but not the actual relations.

    To add the missing relations in the target database you could write ALTER TABLE ... ADD CONSTRAINT ... statements, or use the Diagram Editor again on the target database, or you can try using a database diff tool.