Dienstag, 7. Juli 2015

SQL Server: shrink all transaction logs in an instance



EXEC sp_msForEachDB 'PRINT ''
USE ?
GO
ALTER DATABASE ? SET RECOVERY SIMPLE
GO
DBCC SHRINKFILE(''''?_log'''',1)
GO
ALTER DATABASE ? SET RECOVERY FULL
GO''
'

Windows: How to manually extend the evaluation period

When the initial 60-day evaluation period nears its end, you can run the Slmgr.vbs script to reset the evaluation period. To do this, follow these steps:
  1. Click Start, and then click Command Prompt.
  2. Type slmgr.vbs -dli, and then press ENTER to check the current status of your evaluation period.
  3. To reset the evaluation period, type slmgr.vbs –rearm, and then press ENTER.
  4. Restart the computer.
This resets the evaluation period to 60 days.

Mittwoch, 1. Juli 2015

SQL Server: delete all tables in a database



EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
EXEC sp_MSForEachTable 'ALTER TABLE ? DISABLE TRIGGER ALL'
EXEC sp_MSForEachTable 'DELETE FROM ?'
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
EXEC sp_MSForEachTable 'ALTER TABLE ? ENABLE TRIGGER ALL'

SQL Server: determine deadlocks



Use Master



SELECT

       xed.value('@timestamp', 'datetime') as Creation_Date,

       xed.query('.') AS Extend_Event

FROM

(

       SELECT CAST([target_data] AS XML) AS Target_Data

       FROM sys.dm_xe_session_targets AS xt

       INNER JOIN sys.dm_xe_sessions AS xs

       ON xs.address = xt.event_session_address

       WHERE xs.name = N'system_health'

       AND xt.target_name = N'ring_buffer'

) AS XML_Data

CROSS APPLY Target_Data.nodes('RingBufferTarget/event[@name="xml_deadlock_report"]') AS XEventData(xed)

ORDER BY Creation_Date DESC