Ah - so it is schema related.
Well, it's definitely compatible with SQL 2019... and we also have no idea why or how that happened. We don't see other users having this issue.
We also tested 00. EnsureDbo.sql works on just about every configuration we could imagine:
- user has no schema
- user has different schema
- user has own schema
- user doesn't have permission to change schema
- etc.
What does SELECT SCHEMA_NAME() return?
Any idea why the following isn't working for you?
IF (SCHEMA_NAME() <> 'dbo') BEGIN
DECLARE @SQL NVARCHAR(MAX) = 'ALTER USER [' + CURRENT_USER + '] WITH DEFAULT_SCHEMA = [dbo]'
PRINT 'Changing default schema ("' + SCHEMA_NAME() + '") to dbo via: ' + @SQL
EXEC sp_executesql @SQL
PRINT 'Schema changed.'
END
FYI, here is Microsoft's docs on SCHEMA_NAME:
https://learn.microsoft.com/en-us/sql/t-sql/functions/schema-name-transact-sql


