SQLServer

SQLServer 主キーの追加

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
USE [DB1]
GO
ALTER TABLE [table1] ADD PRIMARY KEY ([col1], [col2])
GO
↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

※PRIMARY KEYを設定する列⇒NOT NULLが必要になる
・nullable → not null

alter table [table1] alter column [col1] [nvarchar(20)] not null;

・not null → nullable

alter table [table1] alter column [col1] [nvarchar(20)] null;