简体   繁体   English

SQL-添加唯一约束失败

[英]SQL - Add Unique Constraint Failure

Trying to alter a table in SQL Server. 尝试在SQL Server中更改表。 I want to add a unique constraint to a column called Names in table ReportingItemNames : 我想向表ReportingItemNames名为Names的列添加唯一约束:

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 目标表或视图中不存在列名“ ReportingItemNames,Name”

Where am I going wrong? 我要去哪里错了?

Use this: 用这个:

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

You can refer to ALTER TABLE (Transact-SQL) documentation for more information. 您可以参考ALTER TABLE(Transact-SQL)文档以获取更多信息。

Shouldn't it be: 不应该是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM