Loading ...
Sorry, an error occurred while loading the content.

[SQL Server]Add Primary Key in SQL Server

Expand Messages
  • vijaya_krishna_birju
    One of the cirtical factor in database/table designing is to prevent duplicate records. There are several ways to do this. You can place Unique Index or Unique
    Message 1 of 1 , Apr 13, 2009
    • 0 Attachment
      One of the cirtical factor in database/table designing is to prevent duplicate records. There are several ways to do this. You can place Unique Index or Unique Constraint or add a primary key. Well there is only slight difference between these things.

      I will go one by one to describe about these but for now lets concentrate on adding a primary key to a table.

      There are two ways to add a primary key constraint:

      1) While Creating the Table using CREATE TABLE command.
      2) Adding Primary key after table creation using ALTER TABLE statement.

      The simple thing is to create the table first and define the Primary key later. Again each one of us will have different opinion but to me this is simple step. Though you will end up in having multiple SQL statements but you will have more control on what you are doing.

      Please check out the below link with detailed examples:

      http://www.dotnetvj.com/2009/03/add-primary-key-in-sql-server.html

      Thanks -- Vj
    Your message has been successfully submitted and would be delivered to recipients shortly.