Hi, I'm trying to do an exercise and have just been introduced to the very basics of SQL. I've made 3 different tables and now I want to add relations between them.

My question is how to make a foreign key? I have a Table "Person" and a table "Phone number". In Table "Person" my primary key is ID and in Table "Phone" my primary key is Phone number. I want key to also be a foreign key that points on ID in Table "Person".

In order to do so I added ID as a column in table "Phone number" as well, right clicked on it and chose relationships. Then I choose Person as the "primary key table" and refered to ID as the primary key and on the right side of the screen I picked ID as the foreign key in "Phone" table.

So no I have a ID in Phone table that is a foreign key to an ID in Person table... that's not what I want :S Any suggestions?

3 Comments:

  1. Anonymous10:07

    FOREIGN KEY (column name) REFERENCES other table name(other column)

    i hope this helped

    ReplyDelete
  2. Anonymous10:07

    ugh I'm not really good with MS SQL
    but check this site :

    http://www.w3schools.com/sql/sql_foreignkey.asp

    ReplyDelete
  3. Anonymous10:08

    I think I know how to do it... my problem is just that... a foreign key must always point at a primary key, but the types and names have to match, so I'm a bit confused

    ReplyDelete

Powered by Blogger.
 
Help-Buzz © 2013. All Rights Reserved. Powered by Blogger
Top