sqlserver如何判断某字段做唯一索引,而且是单独
Posted Ender.Lu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sqlserver如何判断某字段做唯一索引,而且是单独相关的知识,希望对你有一定的参考价值。
IF ( SELECT COUNT(*) FROM sys.index_columns INNER JOIN sys.indexes ON indexes.index_id = index_columns.index_id AND indexes.object_id = index_columns.object_id INNER JOIN sys.columns ON columns.column_id = index_columns.column_id AND columns.object_id = indexes.object_id WHERE indexes.object_id=OBJECT_ID(N‘dbo.tblEnh_SuppQuo‘, N‘U‘) AND indexes.is_unique=1 AND columns.name =N‘InternalQuoNo‘ )=1 BEGIN SELECT 1 END
或者
IF ( SELECT COUNT(*) FROM sys.index_columns INNER JOIN sys.indexes ON indexes.index_id = index_columns.index_id AND indexes.object_id = index_columns.object_id INNER JOIN sys.columns ON columns.column_id = index_columns.column_id AND columns.object_id = indexes.object_id INNER JOIN sys.objects ON objects.object_id = indexes.object_id WHERE objects.name=N‘tblEnh_SuppQuo‘ AND objects.schema_id=1 AND objects.type=N‘U‘ and indexes.is_unique=1 AND columns.name =N‘InternalQuoNo‘ )=1 BEGIN SELECT 1 END
以上是关于sqlserver如何判断某字段做唯一索引,而且是单独的主要内容,如果未能解决你的问题,请参考以下文章