title: Primary key constraint and unique constraint defined on the same column of a table
body: <p>Today I came across a scenario where I observed that SQL Server actually allows us to create both a primary key constraint and a unique constraint on the same column. I expected that it wouldn't throw any error syntactically.</p>
  
  <p>I tested it out and it seems to work fine.</p>
  
  <p>Sample code:</p>
  
  <pre><code>CREATE TABLE testtable
  (
      id INT IDENTITY(1,1),
      name VARCHAR(10),
  
      CONSTRAINT PK_ID PRIMARY KEY (id),
      CONSTRAINT uk_id UNIQUE (id)
  )
  </code></pre>
  
  <p>I also saw that it created a PK constraint and unique constraint separately. </p>
  
  <p>I wanted to get your thoughts on what would be the advantages of having this unique key separately created?</p>
  
  <p>Would it be a good practice to always create a unique constraint along with the primary key? If the answer is "No", in what cases would it be advantageous.</p>
  
  <p>I feel like its a very basic question, but I wanted to get some experts thoughts and advise.</p>
  
  <p>Thank you.</p>