SQL 2014, Set Primary Key, Remove Primary Key in Table




I still do not understand why I can not change data type of field and also if I would like to set "Allow Null" to be "Not Allow Null" then SQL Server stop my dream.

For set primary key in Table of SQL server that very easy, you just click right on the field and select "Set to be primary key" That's it!.

STEP-1
Click right on the field then select "Set Primary Key" but please be sure that field is not allow null and have no double data in field.

Or you can hard code by (Open New Query)
This can set multiple primary key in the same time (Please do not push in Execute ^_^)
ALTER TABLE tb_name ADD PRIMARY KEY (primarykey1,primarykey2)



STEP-2
After you have execute you have to refresh table and click right select "Design", then you will see now you already have primary key in your table.




How to remove Primary Key ?
Click right on the table and select "Design", you will see your fields and attributes of each field then you will see a key icon in front of field was primary key, you have to click right on that primary key field then select "Remove primary key" as image below.





Beware!
- If you want to set a field is primary key, must be sure that field is not allow null
- You have to be sure that field is unique data
- If you created field is not null before, you have to changed to null by use

ALTER TABLE tb_name ALTER COLUMN field_primary int not null


Special STEP Simple

Go to Tool -> Option -> Design then remove checked list as detail below
- Warn about different detection
- Warn about tables affected
- Prevent saving changes that require table re-creation


Good Luck and ENJOIN!