Search code examples
sql-servercreate-table

How to set partial key in sql server


I want to create table and set column as partial key

Fox example:
I create 2 column month and year, then I want to set each column as partial key.

How to do this?


Solution

  • ALTER TABLE dbo.table ADD CONSTRAINT PK_keyname PRIMARY KEY (month, year)
    

    That will create a primary key with month and year as the 2 columns that make up the full key.