SQL Server 2008------There is a syntax error near'unique'

(1) Delete the constraint that the student's name must take a unique value

The solution to the problem of grammatical error near'unique' is as follows:

Note that sql server 2008 applies to delete constraint statements: alter table student drop constraint constraint name

Look up the key in the database table, and then find the name of the constraint key corresponding to the attribute, put it in the statement and delete it

 

ALTER  TABLE  student

DROP  CONSTRAINT  UNQ_student_sname

Note: It is different from the ALTER TABLE Student DROP UNIQUE(Sname); in the textbook; SQL Server 2008 will report an error when using this statement.

(2) Add the constraint that the student's name must take a unique value

ALTER TABLE dbo.student ADD CONSTRAINT UNQ_student_sname

UNIQUE(sname);

Guess you like

Origin blog.csdn.net/weixin_41987016/article/details/108714146