Primary & Foreign Key

  • What is the simple way to remember Primary and foreign key?

    Why is the ID column in a table declared as a integer datatype?

  • This was removed by the editor as SPAM

  • Just to know what they are.

    The primary key uniquely identifies a row.

    A foreign key is used to relate one table to another. It uses the primary key (or any other unique constraint) to make this relationship.

    This means that the foreign key in most tables is dependent on the primary key. Because of this, you can think of the primary key as coming first. Create a primary key and then you can create foreign keys on other tables to relate to the table you just created a primary key on.

    An IDENTITY doesn't have to be on an integer, but, as you can read in the definition, it's an increasing number. So, it has to be on a number field, but it's very nature. It's a number, so it has to be stored as a number.

    "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 3 posts - 1 through 2 (of 2 total)

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