locked
Linking table? RRS feed

  • Question

  • I wasn't sure where to post this, but in my table, I need to create a row of type Character (which is another table I've designed). I've right-clicked on the table in SQL Server Manager, and selected 'Design'. But doing this doesn't seem possible from that view. So I'm assuming I'll have to script it in SQL. Which code should I use, and how do I apply it to the table?
    Saturday, September 3, 2011 1:31 PM

Answers

  • SQL Server is not the object database. It's impossible to create column that represents another class/table.

    What you can do is to create column that references another table. This called referential integrity

    So do the following:

    1. In the referencing (child) table create column with the type that matches referenced (master) table primary key (for simplicity sake)

    2. Click on "Repationships" icon or menu item (Table Designer menu) - it will open popup where you can define the relation.

    3. Create the index on the newly created column in the child table. This is optional step but would help with performance when SQL Server needs to check referential integrity during deletion of the master row.


    Thank you!

    My blog: http://aboutsqlserver.com

    • Marked as answer by Afr0man Saturday, September 3, 2011 11:50 PM
    Saturday, September 3, 2011 6:15 PM

All replies

  • SQL Server is not the object database. It's impossible to create column that represents another class/table.

    What you can do is to create column that references another table. This called referential integrity

    So do the following:

    1. In the referencing (child) table create column with the type that matches referenced (master) table primary key (for simplicity sake)

    2. Click on "Repationships" icon or menu item (Table Designer menu) - it will open popup where you can define the relation.

    3. Create the index on the newly created column in the child table. This is optional step but would help with performance when SQL Server needs to check referential integrity during deletion of the master row.


    Thank you!

    My blog: http://aboutsqlserver.com

    • Marked as answer by Afr0man Saturday, September 3, 2011 11:50 PM
    Saturday, September 3, 2011 6:15 PM
  • Thanks!
    Saturday, September 3, 2011 11:50 PM