Foreign key and primary key

  • Need help in understanding Foreign key and primary key and how to use them in a table

    Thanks

  • Those are the fundamental building blocks of relational databases. A primary key uniquely identifies a row within a table. A foreign key is used to relate one table to another, usually through the primary key, but it can also be through unique constraints (similar to primary keys, but a little different). These terms are defined in more detail in the link above.

    The SQL Server documentation includes information on how to create a primary key and a foreign key. You can also see additional links there for modifying or dropping primary & foreign keys.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Grant Fritchey, thanks very much but i can't see the link

  • Where it says "relational databases" is a link. There is another at "primary key" and "foreign key" in the second paragraph.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • I always thought it was more like:

    Those are the fundamental building blocks of relational databases. A primary key uniquely identifies a row within the database an individual table. A foreign key is used to relate one database table to another, usually through the primary key, but it can also be through unique constraints (similar to primary keys, but a little different).

  • patrickmcginnis59 10839 (10/22/2014)


    I always thought it was more like:

    Those are the fundamental building blocks of relational databases. A primary key uniquely identifies a row within the database an individual table. A foreign key is used to relate one database table to another, usually through the primary key, but it can also be through unique constraints (similar to primary keys, but a little different).

    Oh fudge.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Edited it. Not sure where my brain was.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply