SQLTeam.com | Weblogs | Forums

Why relation is created itself when creating diagram

when we create new diagram in sql server and after adding tables we find that relationship is created between tables itself without manually doing it
it cannot allow me generate code script for relation
how can copy script for relationship between two tables ???

The foreign key(s) on your diagram were created prior to the creation of the diagram. You can create the script for these foreign keys by generating scripts for all the involved tables.

In Management Studio, right-click the database, choose "Generate Scripts" from the pop-up menu, then proceed through the wizard. Select just the tables you need to generate, and create the script to a new window. You can then edit the script to only include the foreign key creation (ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY...)

1 Like