Andrunevchyn

Andrunevchyn


November 2016
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
282930  

Categories


MS SqlServer: unique statement

Andriy AndrunevchynAndriy Andrunevchyn

Don’t use  UNIQUE statement like

LOGIN varchar(100) NOT NULL UNIQUE

SqlServer will create constraint with random name like UQ__TableName__E39E26653F9E5D18

If you use some automation tool like Flyway you will not be able remove that constraint easily because each time when you recreate table you will get new constraint name

Better solution is following

CONSTRAINT UQ__TableName__LOGIN UNIQUE(LOGIN)

in such case you can be sure query

ALTER TABLE [dbo].[USERS] DROP CONSTRAINT UQ__USERS__E39E26653F9E5D18

will work properly

andriy@andrunevchyn.com

Comments 0
There are currently no comments.