MathLover
MathLover

Reputation: 75

SQL - Add Unique Constraint Failure

Trying to alter a table in SQL Server. I want to add a unique constraint to a column called Names in table ReportingItemNames:

ALTER TABLE ReportingItemNames
  ADD CONSTRAINT UC_ReportingItemNames$Name UNIQUE ([ReportingItemNames,Name])

But I am getting this error:

Column name 'ReportingItemNames,Name' does not exist in the target table or view

Where am I going wrong?

Upvotes: 0

Views: 164

Answers (2)

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33381

Use this:

ALTER TABLE ReportingItemNames
           ADD CONSTRAINT UC_ReportingItemNames UNIQUE ([Name])

You can refer to ALTER TABLE (Transact-SQL) documentation for more information.

Upvotes: 3

frlan
frlan

Reputation: 7270

Shouldn't it be:

ALTER TABLE ReportingItemNames
    ADD CONSTRAINT UC_ReportingItemNames$Name UNIQUE ([Name])

Upvotes: 1

Related Questions