Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Create statements that automatically list missing indexes on tmstamp

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

SELECT o. Name username (o.uid), 'ALTER TABLE [dbo].' +'['+ object_name (co.id) / * tbname*/+']'+ 'ADD CONSTRAINT [TM_UNIQUE_'+''+upper (object_name (co.id)) +'] UNIQUE NONCLUSTERED ('+ upper (co.name) / * colname*/+' ASC)'

FROM syscolumns co

Inner join sysobjects o

On co.id=o.id and o. Xtypee properties U' and o. Nameplate 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 (1mai 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. Typewriter U'

Where Col.Name='TMSTAMP' and user_name (o.uid) = 'dbo'-- order by tab.name

) order by object_name (co.id)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report