SQL: When working with ALTER DATABASE, don't forget CURRENT
I’ve been seeing quite a lot of unnecessary dynamic SQL code lately, that’s related to ALTER DATABASE statements. It was part of code that was being scripted.
Generally, the code looks something like this:
DECLARE @SQL nvarchar(max);
SET @SQL = N'ALTER DATABASE '
+ DB_NAME()
+ ' SET COMPATIBILITY_LEVEL = 150;';
EXEC (@SQL);
(I’ve used setting a db_compat level as an example)
Or if it’s slightly more reliable code, it says this:
2020-04-09