21.07.2008, 21:27
|
#11
|
Участник
Регистрация: 28.11.2005
Адрес: Москва
|
Цитата:
Сообщение от Didukh84
а где можно его можно найти
Давным-давно заморачивался этим вопросом, в ходе поиска по тырнету нашел скрипт для Ms SQL, который выдает полезную информацию по таблицам, используя то, что сообщает хранимка sp_spaceused. Все данные о размере, выдаваемые ей, выводятся в kb, но подстрока " KB" удаляется, чтоб удобней было обрабатывать выхлоп в том же Excel.
Вот немного доработанный мною вариант скрипта (авторские комментарии сохранены):
PHP код:
set nocount on
/*
DATABASE TABLE SPY SCRIPT
Micheal Soelter
1/24/03
DESCRIPTION
returns table size information
SORTING USAGE
@sort bit values
0 = alphabetically by table name
1 = sorted by total space used by table
*/
declare @cmdstr varchar(100)
declare @Sort bit
select @sort = 1 /* edit this value for sorting options */
/* DO NOT EDIT ANY CODE BELOW THIS LINE */
--create temporary table
if object_id('tempdb..#temptable') is not null drop table #temptable
create table #temptable
( table_name varchar(100),
row_count int,
table_size_str char(15),
data_space_used_str char(15),
idx_space_used_str char(15),
unused_space_str char(15),
table_size int,
data_space_used int,
idx_space_used int,
unused_space int
)
--create stored procedure string
select @cmdstr = 'sp_msforeachtable ''sp_spaceused "?"'''
--populate tempoary table
insert into #temptable (table_name, row_count, table_size_str, data_space_used_str,
idx_space_used_str, unused_space_str)
exec(@cmdstr)
--determine sorting method
update #temptable
set table_size = cast(replace(table_size_str, ' KB', '') as int),
data_space_used = cast(replace(data_space_used_str, ' KB', '') as int),
idx_space_used = cast(replace(idx_space_used_str, ' KB', '') as int),
unused_space = cast(replace(unused_space_str, ' KB', '') as int)
if @sort = 0
begin
--retrieve table data and sort alphabetically
select table_name, row_count, table_size, data_space_used, idx_space_used, unused_space
from #temptable order by table_name
end
else
begin
--retrieve table data and sort by the size of the table
select table_name, row_count, table_size, data_space_used, idx_space_used, unused_space
from #temptable order by table_size desc
end
--delete temporay table
drop table #temptable
|
|
За это сообщение автора поблагодарили: Denicce (1), aidsua (1), MikeR (1), Didukh84 (1). |