查询唯一索引,添加唯一索引,删除唯一索引

查询

SELECT a.name IndexName,d.COLUMN_NAME,d.ORDINAL_POSITION
FROM sys.indexes a (NOLOCK)
INNER JOIN sys.index_columns b (NOLOCK) ON a.object_id = b.object_id and a.index_id = b.index_id
INNER JOIN sysindexkeys c (NOLOCK) ON a.object_id = c.id and b.index_id = c.indid and b.column_id = c.colid
INNER JOIN INFORMATION_SCHEMA.COLUMNS d (NOLOCK) ON a.object_id = object_id(d.TABLE_NAME) and c.keyno = d.ORDINAL_POSITION
WHERE a.object_id = object_id(N'表名称')

 

添加已有行的唯一索引

 

CREATE UNIQUE INDEX SZYDWORKFLOWSET_DWBH ON SZYDWORKFLOWSET(DWBH);

 

 

删除唯一索引

 

ALTER TABLE GSPUSEROFREGION DROP CONSTRAINT DWBH;

posted @ 2020-11-24 14:47  泉城余文乐  Views(209)  Comments(0Edit  收藏  举报