Latest Posts Under: SQL Server

The day of the week can be retrieved in SQL Server by using the DatePart function. The value returned by function is between 1 (Sunday) and 7 (Saturday). To convert this to a string representing the day of the week, use a CASE statement. Method 1: Create function running following script: CREATE FUNCTION dbo.udf_DayOfWeek(@dtDate DATETIME)… Read Article →

This is a SQL Script that Cleans your Database Records & resets Identity Columns, and it is all in 6 lines! /*Disable Constraints & Triggers*/ exec sp_MSforeachtable ‘ALTER TABLE ? NOCHECK CONSTRAINT ALL’ exec sp_MSforeachtable ‘ALTER TABLE ? DISABLE TRIGGER ALL’ /*Perform delete operation on all table for cleanup*/ exec sp_MSforeachtable ‘DELETE ?’ /*Enable Constraints… Read Article →

Simply start a new query window for the database and use the statement below: SELECT object_name(i.object_id) as objectName, i.[name] as indexName, sum(a.total_pages) as totalPages, sum(a.used_pages) as usedPages, sum(a.data_pages) as dataPages, (sum(a.total_pages) * 8 ) / 1024 as totalSpaceMB, (sum(a.used_pages) * 8 ) / 1024 as usedSpaceMB, (sum(a.data_pages) * 8 ) / 1024 as dataSpaceMB FROM… Read Article →

Scroll To Top