CREATE TABLE
, , .
, contraint , sql- , , ..
1. Let insert some value in our
1. insert into
2. insert into
Unique key violation error displayed by sql server along with constraint name.
**Msg 2627, Level 14, State 1, Line 5
Violation of UNIQUE KEY constraint **'UQ__#Tempbox__737584F6A146D511'**. Cannot insert duplicate key in object 'dbo.#Tempbox'. The duplicate key value is (dsaf).
The statement has been terminated.**
now you got the name of the constraint 'UQ __ # Tempbox__737584F6A146D511'
now leave the constrained column. Remember that you cannot delete a column if it uses a constraint, therefore, to remove this column, you will need to delete the first constraint after the column as well.
ALTER TABLE #Tempbox drop constraint UQ__#Tempbox__737584F6A146D511; -- constraint is dropped
now release the column
alter table
Now use the same procedure for the primary key column
INSERT INTO
INSERT INTO
Error:
Msg 2627, Level 14, State 1, Line 3
Violation of PRIMARY KEY constraint **'PK__#Tempbox__3214EC07B3D09900'**. Cannot insert duplicate key in object 'dbo.#Tempbox'. The duplicate key value is (1).
The statement has been terminated.
drop limit and drop column.
Another way to find the name of the constraint ..
USE Adventure
SELECT CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE CONSTRAINT_TYPE='PRIMARY KEY' AND TABLE_SCHEMA='pERSON' AND TABLE_NAME='PERSON'