自动列出在tmstamp上所缺失索引的创建语句
短信预约 -IT技能 免费直播动态提醒
SELECT o.name,user_name(o.uid),'ALTER TABLE [dbo].'+'['+object_name(co.id) +']'+' ADD CONSTRAINT [TM_UNIQUE_'+''+upper(object_name(co.id))+'] UNIQUE NONCLUSTERED ('+upper(co.name) +' ASC)'
FROM syscolumns co
inner join sysobjects o
on co.id=o.id and o.xtype='U' and o.name<>'dtproperties'
WHERE co.name='TMSTAMP' and user_name(o.uid)='dbo' --order by o.name
and object_name(co.id) not in (
select tab.Name as Tab_Name
from sys.indexes ind
inner join sys.tables tab on ind.Object_id = tab.object_id and ind.type in (1,2)
inner join sys.index_columns index_columns on tab.object_id = index_columns.object_id and ind.index_id = index_columns.index_id
inner join sys.columns Col on tab.object_id = Col.object_id and index_columns.column_id = Col.column_id
left join sysobjects o on tab.name=o.name and o.type='U'
where Col.Name='TMSTAMP' and user_name(o.uid)='dbo' --order by tab.name
) order by object_name(co.id)
FROM syscolumns co
inner join sysobjects o
on co.id=o.id and o.xtype='U' and o.name<>'dtproperties'
WHERE co.name='TMSTAMP' and user_name(o.uid)='dbo' --order by o.name
and object_name(co.id) not in (
select tab.Name as Tab_Name
from sys.indexes ind
inner join sys.tables tab on ind.Object_id = tab.object_id and ind.type in (1,2)
inner join sys.index_columns index_columns on tab.object_id = index_columns.object_id and ind.index_id = index_columns.index_id
inner join sys.columns Col on tab.object_id = Col.object_id and index_columns.column_id = Col.column_id
left join sysobjects o on tab.name=o.name and o.type='U'
where Col.Name='TMSTAMP' and user_name(o.uid)='dbo' --order by tab.name
) order by object_name(co.id)
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341