locked
Database diagrams RRS feed

  • Question

  • Hi!

    I have created a database for a hematology laboratory in a hospital. I want to design a database diagram for the tables'patient', 'BornMarrow'and  'T Biopsy' the common attribute for the tables is 'BHT No.' I created a database diagrams and inserted the tables into it but I don't know how co create relationships between tables. How to do so??????

    Saturday, April 27, 2013 2:03 PM

Answers

  • You can add a FOREIGN KEY constraint the following way:

    ALTER TABLE [Production].[Product]  WITH CHECK ADD  
    CONSTRAINT [FK_ProductSubcategory] FOREIGN KEY([ProductSubcategoryID])
    REFERENCES [Production].[ProductSubcategory] ([ProductSubcategoryID])
    GO

    You can also use the GUI SSMS diagram tool to add the FK constraint.

    Kalman Toth Database & OLAP Architect sqlusa.com
    New Book / Kindle: Pass SQL Exam 70-461 & Job Interview: Programming SQL Server 2012

    Saturday, April 27, 2013 3:53 PM

All replies

  • It's better to create those relationships between the tables beforehand and then create the Database Diagrams, then you would be able to see their relationships diagrammatically.

    BTW - How did you create those diagrams ? Is it through SSMS?


    Narsimha


    • Edited by Naarasimha Saturday, April 27, 2013 3:24 PM
    Saturday, April 27, 2013 3:21 PM
  • You can add a FOREIGN KEY constraint the following way:

    ALTER TABLE [Production].[Product]  WITH CHECK ADD  
    CONSTRAINT [FK_ProductSubcategory] FOREIGN KEY([ProductSubcategoryID])
    REFERENCES [Production].[ProductSubcategory] ([ProductSubcategoryID])
    GO

    You can also use the GUI SSMS diagram tool to add the FK constraint.

    Kalman Toth Database & OLAP Architect sqlusa.com
    New Book / Kindle: Pass SQL Exam 70-461 & Job Interview: Programming SQL Server 2012

    Saturday, April 27, 2013 3:53 PM