create constraint sql server code example
Example: sql server create constraint
ALTER TABLE my_table ALTER COLUMN [Name] VARCHAR(50) NOT NULL;
ALTER TABLE my_table ADD CONSTRAINT UQ__Constrai UNIQUE (ID);
ALTER TABLE my_table ADD PRIMARY KEY (ID);
-- Get constraints names
SELECT CONSTRAINT_NAME,
TABLE_SCHEMA ,
TABLE_NAME,
CONSTRAINT_TYPE
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE TABLE_NAME='my_table';
ALTER TABLE my_table DROP CONSTRAINT PK__Constrai__xxxxx;