查询唯一索引,添加唯一索引,删除唯一索引
查询
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;