January 2017 Entries

SQL Server: How can I tell if a table is being used?
This statement will display the datetime stamp of the last user scan and the last user update. It will also include the # of user updates on that table.

SELECT OBJECT_NAME(OBJECT_ID) AS DatabaseName, last_user_update,*
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID( 'yourDatabaseName')
AND OBJECT_ID=OBJECT_ID('yourTableName')

Posted On Thursday, January 5, 2017 10:15 PM | Comments (0)

SQL Server: How do I test for the existence of a temp (#temp) table before dropping it?
This statement will work 

if object_id('tempdb..#mytempTbl') is not null
  drop table #mytempTbl

Posted On Thursday, January 5, 2017 10:00 PM | Comments (0)