生成指定表rebuild所有索引的語句

2021-08-26 17:11:18 字數 817 閱讀 6163

需要對錶大資料量操作的時候,如delete,需要對索引可以選擇性的操作!可以使用下面語句生成:

declare @tname varchar(100)

declare @size int

set @size=0 --這裡設定索引大小限制,如果不設定預設為0即所有索引

set @tname='tblorders'

select 'alter index '+' '+c.indexname+' '+'on'+' '+@tname+' '+'rebuild with (data_compression=page)'

from

(select * from

(select

object_name(i.object_id) as tablename,

i.name as indexname,

i.index_id as indexid,

8 * sum(a.used_pages)/1024 as 'indexsize(mb)'

from sys.indexes as i

join sys.partitions as p on p.object_id = i.object_id and p.index_id = i.index_id

join sys.allocation_units as a on a.container_id = p.partition_id

group by i.object_id,i.index_id,i.name

)awhere a.tablename=@tname and

[indexsize(mb)]>@size )c

oracle刪除指定使用者所有表

1 select drop table table name from all tables where owner 要刪除的使用者名稱 注意要大寫 2 刪除所有表 以使用者test為例 for example declare cursor cur1 is select table name fro...

刪除指定表的所有索引

刪除指定表的所有索引,包括主鍵索引,唯一索引和普通索引 呼叫 declare tbname varchar 20 set tbname a exec sp dropindex tbname vivianfdlpw 2005.9 引用情保留此資訊 if exists select 1 from sys...

刪除指定表的所有索引

刪除指定表的所有索引 刪除指定表的所有索引,包括主鍵索引,唯一索引和普通索引 呼叫 declare tbname varchar 20 set tbname a exec sp dropindex tbname vivianfdlpw 2005.9 引用情保留此資訊 if exists select...