テーブルのサイズ
テーブルのサイズやインデックスのサイズを表示する SQL 文です。
create table #t ( name nvarchar(256), rows int, reserved nvarchar(256), data nvarchar(256), index_size nvarchar(256), unused nvarchar(256) ) declare c cursor fast_forward for select name from sys.tables open c declare @n nvarchar(255) fetch next from c into @n while (@@fetch_status <> -1) begin insert into #t exec sp_spaceused @n fetch next from c into @n end close c deallocate c select * from #t drop table #t
出力例
name | rows | reserved | data | index_size | unused |
---|---|---|---|---|---|
Categories | 8 | 168 KB | 112 KB | 24 KB | 32 KB |
Customers | 91 | 104 KB | 24 KB | 80 KB | 0 KB |
Shippers | 3 | 16 KB | 8 KB | 8 KB | 0 KB |
Suppliers | 29 | 64 KB | 24 KB | 40 KB | 0 KB |
Orders | 830 | 504 KB | 160 KB | 320 KB | 24 KB |
以下を参照しました。
【SQLServer】一時テーブルを利用したカーソル操作 | ”熱狂するシステム開発!”ブログ
SQLServerのストアドプロシージャ記述に関する質問があります。
あるプロシージャ内において、別のストアドプロシージャから返される結果セットを受け取って使用したく思います。
たとえば、sp_lockなどのシステムプロシージャや自分で記述したプロシージャの結果セットを、
SELECT文のテーブルのように使ったり、一時表に入れ込んだり、などの方法が便利です。
システムストアドプロシージャも使用したいので、関数(FUNCTION)での代用は出来ません。
ご存知の方、ぜひご教示下さい。ヒントでも結構です。
(sp_tablesをsysobjectsから拾う、などは互換性の問題もあり(ServicePack適用で値が変わるかも...)あまりやりたくありません)