Skip to main content

Joseph Sack’s Article: Seven SHOWPLAN Red Flags

Joseph Sack over at SQL Server Centralhas written a short article on query optimisation using Query Analyzer’s graphical Show Plan. Certainly an under used resource, show plan can actually give you insight to how SQL Server intends to / did run your query, and where high i/o or cpu taxing tasks are undertaken. Joseph’s article […]

Collation Conflicts

If you’ve ever worked with databases from different sources, or with different collation settings, you’ve probably encountered an error like this: Msg 468, Level 16, State 9, Line 1 Cannot resolve collation conflict between ‘Latin1_General_CI_AS’ and ‘SQL_Latin1_General_CP1_CI_AS’ in equal to operation. The error is cause by having different collation settings for the columns in the […]

Moving Tempdb

So somebody setup sql server and you now want to move tempdb to another drive? Easy. Fire up Query Analyser and run the commands: ALTER DATABASE tempdb MODIFY FILE (name = ‘tempdev’, filename = ‘new-file-path‘) ALTER DATABASE tempdb MODIFY FILE (name = ‘templog’, filename = ‘new-file-path‘) Replace the new-file-path with the full path and filename […]

Snippet: Select a Date or Current Date Without Time

Often you’ll want to compare datetime values based on the date only, ignoring the time. This is especially important when doing date ranges, where thinking like a human you might want ‘Select Accounts Join Offers Where SignupDate between 1st Jan and 31st Jan’. As a human we’re probably thinking ‘inclusive’. As a computer, SQL Server […]

Snippet: Show full column names and data types for all user tables in a database

SELECT QUOTENAME( ) + ‘.’ + QUOTENAME( USER_NAME( sysobjects.uid ) ) + ‘.’ + QUOTENAME( ) AS [Name] , TYPE_NAME( syscolumns.xusertype ) AS [Type] , syscolumns.prec AS [Precision] , syscolumns.scale AS [Scale] FROM syscolumnsINNER JOIN sysobjects ON = sysobjects.idLEFT OUTER JOIN systypes ON systypes.xtype = syscolumns.xtypeWHERE sysobjects.xtype = ‘U’