How to create a composite primary key in the table Design window

  • In your SSMS, open the table (use tblPSMOrderDetail as an example) in Design


  • Click one column (OrderID), then press and hold Ctrl key, then click the other column that will be part of the primary key (ProductID). Now the two should be highlighted as shown below


  • Right click the left side of the table Design window, then choose Set Primary Key


  • After that, the two columns should be marked with the golden key indicating the two columns form the composite primary key for the table. Make sure to save the changes of the table design



How to create a unique column using the SSMS GUI. Later, you will learn how to use DDL to create a unique column

  • In this example, we will make ProductName column in tblPSMProduct table to be unique


  • Make sure the table is not open in Design! Right click the Indexes folder under the table, then select New Index->Non-Clustered Index


  • The New Index window comes up. Check the Unique checkbox. Click Add button to select the column(s)


  • The Select Columns window comes up. Choose the column(s) that need to be unique. In this example, we create a single unique column, so we only choose one column ProductName. If you want to create a composite unique column, you choose all the columns for the unique column.


  • Click OK to complete the task