Problem: How to create a
database diagram to understand the table relations inside a database.
Given any new database it’s hard to find the relations
between each tables and foreign keys to use joins on the tables, As the
architecture is tough to understand for the first time the diagram will help us
to solve the links between each tables and columns in each table. It basically
gives a direction to navigate as a map to the database.
To create a database diagram, you must have a DB owner
permission on the database or a login that has valid ownership or else the
database diagram will throw the following error.
To get over this error you may have to authorize the
database as owner
ALTER AUTHORIZATION ON DATABASE::AdventureWorks2014 TO sa;
Example:
In this example, I would like to show we can create a
database diagram and add related tables to create a diagram structure also to
show the labels of the foreign key relationships.
Step 1:
launch the SSMS and navigate through the databases folder and select the
database you want to build the database diagrams for.
Step 2: right
click to add new database diagram from the database diagrams.
Step 3:
after this a dialog box, will be prompted to accept and hit yes.
Step 4: on
the next step, you must select a table you wish get an understanding on.
Step 5:
after the table, has been selected right click on the table to add its related
tables. You should now get a relational diagram.
Step 6: in
the additional efforts, you can right click on the open area to add
relationship labels to see the foreign key constraints from the tables.
Results:
0 comments:
Post a Comment