Friday, 8 May 2009
How to find the Database Restore Details in SQL Server 2008
SELECT
rsh.destination_database_name AS [Database],
rsh.user_name AS [Restored By],
CASE WHEN rsh.restore_type = 'D' THEN 'Database'
WHEN rsh.restore_type = 'F' THEN 'File'
WHEN rsh.restore_type = 'G' THEN 'Filegroup'
WHEN rsh.restore_type = 'I' THEN 'Differential'
WHEN rsh.restore_type = 'L' THEN 'Log'
WHEN rsh.restore_type = 'V' THEN 'Verifyonly'
WHEN rsh.restore_type = 'R' THEN 'Revert'
ELSE rsh.restore_type
END AS [Restore Type],
rsh.restore_date AS [Restore Started],
bmf.physical_device_name AS [Restored From],
rf.destination_phys_name AS [Restored To]
FROM msdb.dbo.restorehistory rsh
INNER JOIN msdb.dbo.backupset bs ON rsh.backup_set_id = bs.backup_set_id
INNER JOIN msdb.dbo.restorefile rf ON rsh.restore_history_id = rf.restore_history_id
INNER JOIN msdb.dbo.backupmediafamily bmf ON bmf.media_set_id = bs.media_set_id
You can apply filter criteria such as the restore date , Database by addding a where clause to the existing query as shown below
WHERE
rsh.restore_date >= DATEADD(dd, "No of Past Days" , GETDATE())
AND destination_database_name = ISNULL( "DB Name", destination_database_name)
ORDER BY rsh.restore_history_id DESC
Tuesday, 5 May 2009
SQL Server 2008 - Performance white paper
- CPU Bottlenecks
- Memory Bottlenecks
- IO Bottlenecks
- Temp DB
- Slow Running Queries
- Extended Events
- Data Collector & MDV
http://msdn.microsoft.com/en-us/library/dd672789.aspx
Monday, 13 April 2009
SQL Server 2008 SP1- Released
- SlipStream - The SQL Server 2008 and Service Pack 1 installation can be integrated and installed in a single step.
- Service Pack Uninstall – We can uninstall the service pack alone ( no need to un install the entire service)
- Report Builder 2.0 Click Once capability
It is available for download at
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=66ab3dbb-bf3e-4f46-9559-ccc6a4f9dc19
Wednesday, 11 February 2009
SQL Server 2008 DMV's Relationship mapping
Microsoft has recently released the latest “System Views Map” for SQL Server 2008 which shows the key system views and the relationships between them. You can download the latest System Views Map at
http://www.microsoft.com/downloads/details.aspx?FamilyID=531c53e7-8a2a-4375-8f2f-5d799aa67b5c&displaylang=en
The updated “System views Map” for SQ Server 2005 also can be downloaded at
http://www.microsoft.com/downloads/details.aspx?familyid=2EC9E842-40BE-4321-9B56-92FD3860FB32&displaylang=en
SQL Server Hot Fixes at one place
This blog also contains hot fix information for other Microsoft products such as Windows, Visual Studio, and IE etc. The original blog can be find at
http://blogs.technet.com/hot/archive/tags/SQL+Server/default.aspx
Thursday, 5 February 2009
Reasons for slower Delete in SQL Server
Delete statement plays a major role in many of the database maintenance activities. Extreme care should be taken before executing the DELETE statements
Before executing the DELETE statement it is better to check the “Estimated execution plan”, so that we can create proper indexes to speed up the execution .I have given some of the possible reasons for slower delete.
1. Locking / Blocking - If it is a production database process is having Lock / Block on the table
2. Fragmentation - The Index pages are fragmented due to excessive delete on the table (Defragment the Indexes and try again)
3. The table you are trying to delete is referred by many tables as foreign key and those columns are not indexed.
4. There might be hanging transactions on the table - Try to truncate the Log and do
5. You can also change the Recovery Mode to simple and try - but not advised in case of production DB
Also it is recommended to execute the DELETE statements in smaller batches so that the Log space & Roll back of the records can be easier as shown below
// assume you wanted to delete 100000 records, we can split them into 10 batches as
DECLARE @V_Count INT =0
WHILE @V_Count < 100000
BEGIN
DELETE TOP(10000)
FROM Table
WHERE COLUMN = Condition
SET @V_Count =@V_Count+10000
END
Wednesday, 4 February 2009
Sinlge user mode in SQL Server
if(charindex('Microsoft SQL Server 2005',@@version) > 0)
begin
declare @sql varchar(8000)
select @sql = '
ALTER DATABASE ' + DB_NAME() + ' SET SINGLE_USER WITH ROLLBACK IMMEDIATE ;
ALTER DATABASE ' + DB_NAME() + ' SET READ_COMMITTED_SNAPSHOT ON;
ALTER DATABASE ' + DB_NAME() + ' SET MULTI_USER;'
Exec(@sql)
end
Any changes to Database level properties in SQL Server can be done easily through the use of single user mode, which permits only one connection to be made to the database at any time.