Search
 
SCRIPT & CODE EXAMPLE
 

SQL

set column as unique in sql server

ALTER TABLE Persons
ADD UNIQUE (ID);
Comment

how to set a column as unique in sql server

Set column as unique in SQL Server from the GUI:
They really make you run around the barn to do it with the GUI:

Make sure your column does not violate the unique constraint before you begin.

Open SQL Server Management Studio.
Right click your Table, click "Design".
Right click the column you want to edit, a popup menu appears, click Indexes/Keys.
Click the "Add" Button.
Expand the "General" tab.
Make sure you have the column you want to make unique selected in the "columns" box.
Change the "Type" box to "Unique Key".
Click "Close".
You see a little asterisk in the file window, this means changes are not yet saved.
Press Save or hit Ctrl+s. It should save, and your column should be unique.

Or set column as unique from the SQL Query window:

alter table location_key drop constraint pinky;
alter table your_table add constraint pinky unique(yourcolumn);
Comment

PREVIOUS NEXT
Code Example
Sql :: sql set 
Sql :: com.mysql.cj.exceptions.InvalidConnectionAttributeException more than one time zone. You must configure either the server or JD value if you want to utilize time zone support. 
Sql :: mysql remove records 
Sql :: error code 1215 cannot add foreign key constraint 
Sql :: mysql count by month 
Sql :: change password postgres pgserver 
Sql :: postgres top 10 
Sql :: mysql 8 geo to json 
Sql :: oracle duration between timestamps 
Sql :: sql period overlap 
Sql :: delete data from database sqlite android 
Sql :: mysql function variable 
Sql :: all_dependencies 
Sql :: unique key in ms sql server 
Sql :: postgresql full text search 
Sql :: what is a query in sql 
Sql :: make date with time sql 
Sql :: snowflake select from stage 
Sql :: how to find unique element in sql 
Sql :: mysql create user with grant privileges 
Sql :: mysql not equal 
Sql :: postgres extract time from timestamp 
Sql :: oracle dynamic select into 
Sql :: postgresql change user role grant 
Sql :: sql values to array of objects 
Sql :: mysql on duplicate key ignore 
Sql :: read xml in sql server 
Sql :: mysql expression is not in group by clause 
Sql :: oracle inner join 
Sql :: creating a view in sql 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =