In case you ever needed this: IF OBJECT_ID('tempdb..#GeneratedScripts') IS NOT NULL DROP TABLE #GeneratedScripts; CREATE TABLE #GeneratedScripts (Id INT IDENTITY(1,1), SqlScript NVARCHAR(MAX)); -- 1. Setup global ceiling INSERT INTO #GeneratedScripts (SqlScript) VALUES ('DECLARE @TargetCeiling DATETIME = GETDATE();'); DECLARE @SchemaName NVARCHAR(256), @TableName NVARCHAR(256), @AnchorColumn NVARCHAR(256); DECLARE @Sql NVARCHAR(MAX), @ColumnUpdates NVARCHAR(MAX); DECLARE tbl_cursor CURSOR FOR SELECT DISTINCT … Continue reading Script to update the dates on AdventureWorks database
Tag: SQL Server
Wierd tuning trick with dynamic SQL when encountering unmatched indexes
Later edit: Both Uwe Ricken (https://www.linkedin.com/in/uwericken/, https://www.db-berater.de/) and Sascha Lorenz (https://www.linkedin.com/in/saschalorenz/) correctly pointed out that my little inconsisted writing was a tad too inconsistent - first of all, the title itself was NOT highlighting the very point of this blog post: unmatched indexes and how to deal with them by using dynamic SQL. Truth be … Continue reading Wierd tuning trick with dynamic SQL when encountering unmatched indexes
Stop using variables in stored procedures for no reason
Yes, writing about SQL Server every 10 years will not bring me any medals. I know, I know.Anyway, I am currently checking what is what on a new project and I got to see this in the header of a stored procedure from 10 years ago: "use @variable to suppress 'parameter sniffing'".I will NOT dwelve … Continue reading Stop using variables in stored procedures for no reason
DATETIME and its surprises
Well, it's about time I write another blog post (with a promise that I'll do it more than once a year). I'm going to start a series of "bad habits to kick" as for me it is important that we all have a common ground on SQL Programming. 1. Consider the following scenario: SET … Continue reading DATETIME and its surprises
SQL Server installation tips… NOT
I have to admit that I shamelessly "steal" any info available on the net when it comes to SQL Server. Just to give you a quick example: Brent Ozar and Jonathan Kehayas both have some neat articles about installing SQL Server. Of course, I use the Next > Next > Finish feature, just as anybody … Continue reading SQL Server installation tips… NOT