当前位置:Gxlcms > 数据库问题 > sqlserver如何判断某字段做唯一索引,而且是单独

sqlserver如何判断某字段做唯一索引,而且是单独

时间:2021-07-01 10:21:17 帮助过:5人阅读

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如何判断某字段做唯一索引,而且是单独

标签:ble   unique   alq   schema   name   highlight   column   sch   如何   

人气教程排行