Showing posts with label database property. Show all posts
Showing posts with label database property. Show all posts

Thursday, August 2, 2012

Database Restore History

USE msdb;
GO
Select top 20
DBRestored= destination_database_name,
SourceFile= physical_name,
RestoreDate= restore_date
from RestoreHistory h
inner join BackupSet b
on h.backup_set_id = b.backup_set_id
inner join BackupFile f
on f.backup_set_id = b.backup_set_id
order by RestoreDate desc
GO

MvM

Monday, July 23, 2012

List larger tables in a database

I have tried this query only on sql 2008. This will extract all tables with number of rows, reserved,data,index and unused space in MB.


select

name =object_schema_name(object_id)+'.'+object_name(object_id),

rows =sum(case when index_id < 2 then row_count else 0 end),

reserved_MB = 8*sum(reserved_page_count)/1024,

data_MB = 8*sum(case when index_id<2

then in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count

else lob_used_page_count + row_overflow_used_page_count end)/1024,

index_MB = 8*(sum(used_page_count)-sum(case when index_id<2

then in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count

else lob_used_page_count + row_overflow_used_page_count end))/1024,

unused_kb = 8*sum(reserved_page_count-used_page_count)

from sys.dm_db_partition_stats

where object_id> 1024

group by object_id

order by rows desc;

MvM

List Recovery Model for all databases in SQL Server 2000

Two ways I used to find it. But the best one is the first one listed.




SELECT Name,

DATABASEPROPERTYEX (Name,'RECOVERY') AS [Recovery Model]

FROM master.dbo.sysdatabases

OR


sp_msforeachdb

'use [?] select ''?'' as DatabaseName, DATABASEPROPERTYEX(N''?'', N''RECOVERY'')'


MvM