码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2020-03-18 09:16:58      阅读:83      评论:0      收藏:0      [点我收藏+]

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

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   如何   

原文地址:https://www.cnblogs.com/coolyylu/p/12515257.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!