From 2e0055b81624ab9351ac58e43f9f0bb6cf4140ac Mon Sep 17 00:00:00 2001 From: Andriy Svyryd Date: Thu, 21 Nov 2024 22:00:15 -0800 Subject: [PATCH] Uniquify all variables used in SQL Server migration scripts Fixes #35132 --- .../Migrations/MigrationCommandListBuilder.cs | 12 + .../Storage/IRelationalCommandBuilder.cs | 7 + .../Storage/RelationalCommandBuilder.cs | 10 + .../RelationalCommandBuilderExtensions.cs | 15 + .../SqlServerMigrationsSqlGenerator.cs | 98 ++- .../Migrations/MigrationsSqlServerTest.cs | 830 +++++++++--------- .../SqlServerMigrationsSqlGeneratorTest.cs | 46 +- .../TestRelationalCommandBuilderFactory.cs | 7 + 8 files changed, 545 insertions(+), 480 deletions(-) diff --git a/src/EFCore.Relational/Migrations/MigrationCommandListBuilder.cs b/src/EFCore.Relational/Migrations/MigrationCommandListBuilder.cs index e75d2940d19..dcdcdbb6574 100644 --- a/src/EFCore.Relational/Migrations/MigrationCommandListBuilder.cs +++ b/src/EFCore.Relational/Migrations/MigrationCommandListBuilder.cs @@ -99,6 +99,18 @@ public virtual MigrationCommandListBuilder AppendLine(string value) return this; } + /// + /// Appends the given string to the command being built, and then starts a new line. + /// + /// The string to append. + /// This builder so that additional calls can be chained. + public virtual MigrationCommandListBuilder AppendLine(FormattableString value) + { + _commandBuilder.AppendLine(value); + + return this; + } + /// /// Appends the given object to the command being built as multiple lines of text. That is, /// each line in the passed string is added as a line to the command being built. diff --git a/src/EFCore.Relational/Storage/IRelationalCommandBuilder.cs b/src/EFCore.Relational/Storage/IRelationalCommandBuilder.cs index 7a3da9c6924..c147558f126 100644 --- a/src/EFCore.Relational/Storage/IRelationalCommandBuilder.cs +++ b/src/EFCore.Relational/Storage/IRelationalCommandBuilder.cs @@ -56,6 +56,13 @@ public interface IRelationalCommandBuilder /// The same builder instance so that multiple calls can be chained. IRelationalCommandBuilder Append(string value); + /// + /// Appends an object to the command text. + /// + /// The object to be written. + /// The same builder instance so that multiple calls can be chained. + IRelationalCommandBuilder Append(FormattableString value); + /// /// Appends a blank line to the command text. /// diff --git a/src/EFCore.Relational/Storage/RelationalCommandBuilder.cs b/src/EFCore.Relational/Storage/RelationalCommandBuilder.cs index 04313967eb6..079cf521883 100644 --- a/src/EFCore.Relational/Storage/RelationalCommandBuilder.cs +++ b/src/EFCore.Relational/Storage/RelationalCommandBuilder.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Text; + namespace Microsoft.EntityFrameworkCore.Storage; /// @@ -71,6 +73,14 @@ public virtual IRelationalCommandBuilder Append(string value) return this; } + /// + public virtual IRelationalCommandBuilder Append(FormattableString value) + { + _commandTextBuilder.Append(value); + + return this; + } + /// public virtual IRelationalCommandBuilder AppendLine() { diff --git a/src/EFCore.Relational/Storage/RelationalCommandBuilderExtensions.cs b/src/EFCore.Relational/Storage/RelationalCommandBuilderExtensions.cs index e410a9c695c..ff13faf5f7a 100644 --- a/src/EFCore.Relational/Storage/RelationalCommandBuilderExtensions.cs +++ b/src/EFCore.Relational/Storage/RelationalCommandBuilderExtensions.cs @@ -30,6 +30,21 @@ public static IRelationalCommandBuilder AppendLine( return commandBuilder; } + /// + /// Appends an object to the command text on a new line. + /// + /// The command builder. + /// The object to be written. + /// The same builder instance so that multiple calls can be chained. + public static IRelationalCommandBuilder AppendLine( + this IRelationalCommandBuilder commandBuilder, + FormattableString value) + { + commandBuilder.Append(value).AppendLine(); + + return commandBuilder; + } + /// /// Appends an object, that contains multiple lines of text, to the command text. /// Each line read from the object is appended on a new line. diff --git a/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs b/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs index 14fd173e8d7..625d7e52acd 100644 --- a/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs +++ b/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs @@ -29,7 +29,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations; public class SqlServerMigrationsSqlGenerator : MigrationsSqlGenerator { private IReadOnlyList _operations = null!; - private int _variableCounter; + private int _variableCounter = -1; private readonly ICommandBatchPreparer _commandBatchPreparer; @@ -643,6 +643,8 @@ protected override void Generate( subBuilder.Append(")"); + var historyTableName = operation[SqlServerAnnotationNames.TemporalHistoryTableName] as string; + string historyTable; if (needsExec) { subBuilder @@ -650,18 +652,14 @@ protected override void Generate( var execBody = subBuilder.GetCommandList().Single().CommandText.Replace("'", "''"); + var schemaVariable = Uniquify("@historyTableSchema"); builder - .AppendLine("DECLARE @historyTableSchema sysname = SCHEMA_NAME()") + .AppendLine($"DECLARE {schemaVariable} sysname = SCHEMA_NAME()") .Append("EXEC(N'") .Append(execBody); - } - var historyTableName = operation[SqlServerAnnotationNames.TemporalHistoryTableName] as string; - string historyTable; - if (needsExec) - { historyTable = Dependencies.SqlGenerationHelper.DelimitIdentifier(historyTableName!); - tableCreationOptions.Add($"SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + N'].{historyTable})"); + tableCreationOptions.Add($"SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + {schemaVariable} + N'].{historyTable})"); } else { @@ -1116,10 +1114,11 @@ protected override void Generate( { if (operation[SqlServerAnnotationNames.EditionOptions] is string editionOptions) { + var dbVariable = Uniquify("@db_name"); builder .AppendLine("BEGIN") - .AppendLine("DECLARE @db_name nvarchar(max) = DB_NAME();") - .AppendLine("EXEC(N'ALTER DATABASE [' + @db_name + '] MODIFY ( ") + .AppendLine($"DECLARE {dbVariable} nvarchar(max) = DB_NAME();") + .AppendLine($"EXEC(N'ALTER DATABASE [' + {dbVariable} + '] MODIFY ( ") .Append(editionOptions.Replace("'", "''")) .AppendLine(" );');") .AppendLine("END") @@ -1128,19 +1127,21 @@ protected override void Generate( if (operation.Collation != operation.OldDatabase.Collation) { + var dbVariable = Uniquify("@db_name"); builder .AppendLine("BEGIN") - .AppendLine("DECLARE @db_name nvarchar(max) = DB_NAME();"); + .AppendLine($"DECLARE {dbVariable} nvarchar(max) = DB_NAME();"); + var collation = operation.Collation; if (operation.Collation == null) { - builder.AppendLine("DECLARE @defaultCollation nvarchar(max) = CAST(SERVERPROPERTY('Collation') AS nvarchar(max));"); + var collationVariable = Uniquify("@defaultCollation"); + builder.AppendLine($"DECLARE {collationVariable} nvarchar(max) = CAST(SERVERPROPERTY('Collation') AS nvarchar(max));"); + collation = "' + " + collationVariable + " + N'"; } builder - .Append("EXEC(N'ALTER DATABASE [' + @db_name + '] COLLATE ") - .Append(operation.Collation ?? "' + @defaultCollation + N'") - .AppendLine(";');") + .AppendLine($"EXEC(N'ALTER DATABASE [' + {dbVariable} + '] COLLATE {collation};');") .AppendLine("END") .AppendLine(); } @@ -1167,10 +1168,11 @@ protected override void Generate( using (builder.Indent()) { + var dbVariable = Uniquify("@db_name"); builder .AppendLine("BEGIN") .AppendLine("ALTER DATABASE CURRENT SET AUTO_CLOSE OFF;") - .AppendLine("DECLARE @db_name nvarchar(max) = DB_NAME();") + .AppendLine($"DECLARE {dbVariable} nvarchar(max) = DB_NAME();") .AppendLine("DECLARE @fg_name nvarchar(max);") .AppendLine("SELECT TOP(1) @fg_name = [name] FROM [sys].[filegroups] WHERE [type] = N'FX';") .AppendLine() @@ -1180,20 +1182,21 @@ protected override void Generate( { builder .AppendLine("BEGIN") - .AppendLine("SET @fg_name = @db_name + N'_MODFG';") + .AppendLine($"SET @fg_name = {dbVariable} + N'_MODFG';") .AppendLine("EXEC(N'ALTER DATABASE CURRENT ADD FILEGROUP [' + @fg_name + '] CONTAINS MEMORY_OPTIMIZED_DATA;');") .AppendLine("END"); } + var pathVariable = Uniquify("@path"); builder .AppendLine() - .AppendLine("DECLARE @path nvarchar(max);") - .Append("SELECT TOP(1) @path = [physical_name] FROM [sys].[database_files] ") + .AppendLine($"DECLARE {pathVariable} nvarchar(max);") + .Append($"SELECT TOP(1) {pathVariable} = [physical_name] FROM [sys].[database_files] ") .AppendLine("WHERE charindex('\\', [physical_name]) > 0 ORDER BY [file_id];") - .AppendLine("IF (@path IS NULL)") - .IncrementIndent().AppendLine("SET @path = '\\' + @db_name;").DecrementIndent() + .AppendLine($"IF ({pathVariable} IS NULL)") + .IncrementIndent().AppendLine($"SET {pathVariable} = '\\' + {dbVariable};").DecrementIndent() .AppendLine() - .AppendLine("DECLARE @filename nvarchar(max) = right(@path, charindex('\\', reverse(@path)) - 1);") + .AppendLine($"DECLARE @filename nvarchar(max) = right({pathVariable}, charindex('\\', reverse({pathVariable})) - 1);") .AppendLine( "SET @filename = REPLACE(left(@filename, len(@filename) - charindex('.', reverse(@filename))), '''', '''''') + N'_MOD';") .AppendLine( @@ -1767,10 +1770,11 @@ protected virtual void Transfer( { var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); + var schemaVariable = Uniquify("@defaultSchema"); builder - .AppendLine("DECLARE @defaultSchema sysname = SCHEMA_NAME();") + .AppendLine($"DECLARE {schemaVariable} sysname = SCHEMA_NAME();") .Append("EXEC(") - .Append("N'ALTER SCHEMA [' + @defaultSchema + ") + .Append($"N'ALTER SCHEMA [' + {schemaVariable} + ") .Append( stringTypeMapping.GenerateSqlLiteral( "] TRANSFER " + Dependencies.SqlGenerationHelper.DelimitIdentifier(name, schema) + ";")) @@ -1936,7 +1940,7 @@ protected virtual void DropDefaultConstraint( { var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); - var variable = "@var" + _variableCounter++; + var variable = Uniquify("@var"); builder .Append("DECLARE ") @@ -2067,18 +2071,18 @@ protected virtual void AddDescription( string? column = null, bool omitVariableDeclarations = false) { - string schemaLiteral; + var schemaLiteral = Uniquify("@defaultSchema", increase: !omitVariableDeclarations); + var descriptionVariable = Uniquify("@description", increase: false); + if (schema == null) { if (!omitVariableDeclarations) { - builder.Append("DECLARE @defaultSchema AS sysname") + builder.Append($"DECLARE {schemaLiteral} AS sysname") .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); - builder.Append("SET @defaultSchema = SCHEMA_NAME()") + builder.Append($"SET {schemaLiteral} = SCHEMA_NAME()") .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); } - - schemaLiteral = "@defaultSchema"; } else { @@ -2087,16 +2091,15 @@ protected virtual void AddDescription( if (!omitVariableDeclarations) { - builder.Append("DECLARE @description AS sql_variant") + builder.Append($"DECLARE {descriptionVariable} AS sql_variant") .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); } - builder.Append("SET @description = ") - .Append(Literal(description)) + builder.Append($"SET {descriptionVariable} = {Literal(description)}") .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); builder .Append("EXEC sp_addextendedproperty 'MS_Description', ") - .Append("@description") + .Append(descriptionVariable) .Append(", 'SCHEMA', ") .Append(schemaLiteral) .Append(", 'TABLE', ") @@ -2249,18 +2252,17 @@ protected virtual void DropDescription( { var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); - string schemaLiteral; + var schemaLiteral = Uniquify("@defaultSchema", increase: !omitVariableDeclarations); + var descriptionVariable = Uniquify("@description", increase: false); if (schema == null) { if (!omitVariableDeclarations) { - builder.Append("DECLARE @defaultSchema AS sysname") + builder.Append($"DECLARE {schemaLiteral} AS sysname") .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); - builder.Append("SET @defaultSchema = SCHEMA_NAME()") + builder.Append($"SET {schemaLiteral} = SCHEMA_NAME()") .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); } - - schemaLiteral = "@defaultSchema"; } else { @@ -2269,7 +2271,7 @@ protected virtual void DropDescription( if (!omitVariableDeclarations) { - builder.Append("DECLARE @description AS sql_variant") + builder.Append($"DECLARE {descriptionVariable} AS sql_variant") .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); } @@ -2379,6 +2381,16 @@ private static bool HasDifferences(IEnumerable source, IEnumerable< return count != targetAnnotations.Count; } + private string Uniquify(string variableName, bool increase = true) + { + if (increase) + { + _variableCounter++; + } + + return _variableCounter == 0 ? variableName : variableName + _variableCounter; + } + private IReadOnlyList RewriteOperations( IReadOnlyList migrationOperations, IModel? model, @@ -3071,10 +3083,12 @@ void EnableVersioning(string table, string? schema, string historyTableName, str { var stringBuilder = new StringBuilder(); + string? schemaVariable = null; if (historyTableSchema == null) { + schemaVariable = Uniquify("@historyTableSchema"); // need to run command using EXEC to inject default schema - stringBuilder.AppendLine("DECLARE @historyTableSchema sysname = SCHEMA_NAME()"); + stringBuilder.AppendLine($"DECLARE {schemaVariable} sysname = SCHEMA_NAME()"); stringBuilder.Append("EXEC(N'"); } @@ -3093,7 +3107,7 @@ void EnableVersioning(string table, string? schema, string historyTableName, str else { stringBuilder.AppendLine( - $" SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].{historyTable}))')"); + $" SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + {schemaVariable} + '].{historyTable}))')"); } operations.Add( diff --git a/test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsSqlServerTest.cs index b32e04b8e35..37bc03eadf5 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsSqlServerTest.cs @@ -432,12 +432,12 @@ public override async Task Alter_table_change_comment() AssertSql( """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -EXEC sp_dropextendedproperty 'MS_Description', 'SCHEMA', @defaultSchema, 'TABLE', N'People'; -SET @description = N'Table comment2'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'People'; +DECLARE @defaultSchema1 AS sysname; +SET @defaultSchema1 = SCHEMA_NAME(); +DECLARE @description1 AS sql_variant; +EXEC sp_dropextendedproperty 'MS_Description', 'SCHEMA', @defaultSchema1, 'TABLE', N'People'; +SET @description1 = N'Table comment2'; +EXEC sp_addextendedproperty 'MS_Description', @description1, 'SCHEMA', @defaultSchema1, 'TABLE', N'People'; """); } @@ -447,10 +447,10 @@ public override async Task Alter_table_remove_comment() AssertSql( """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -EXEC sp_dropextendedproperty 'MS_Description', 'SCHEMA', @defaultSchema, 'TABLE', N'People'; +DECLARE @defaultSchema1 AS sysname; +SET @defaultSchema1 = SCHEMA_NAME(); +DECLARE @description1 AS sql_variant; +EXEC sp_dropextendedproperty 'MS_Description', 'SCHEMA', @defaultSchema1, 'TABLE', N'People'; """); } @@ -1110,12 +1110,12 @@ public override async Task Alter_column_change_type() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'SomeColumn'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [SomeColumn] bigint NOT NULL; """); } @@ -1126,12 +1126,12 @@ public override async Task Alter_column_make_required() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'SomeColumn'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); UPDATE [People] SET [SomeColumn] = N'' WHERE [SomeColumn] IS NULL; ALTER TABLE [People] ALTER COLUMN [SomeColumn] nvarchar(max) NOT NULL; ALTER TABLE [People] ADD DEFAULT N'' FOR [SomeColumn]; @@ -1144,12 +1144,12 @@ public override async Task Alter_column_make_required_with_null_data() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'SomeColumn'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); UPDATE [People] SET [SomeColumn] = N'' WHERE [SomeColumn] IS NULL; ALTER TABLE [People] ALTER COLUMN [SomeColumn] nvarchar(max) NOT NULL; ALTER TABLE [People] ADD DEFAULT N'' FOR [SomeColumn]; @@ -1164,12 +1164,12 @@ public override async Task Alter_column_make_required_with_index() AssertSql( """ DROP INDEX [IX_People_SomeColumn] ON [People]; -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'SomeColumn'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); UPDATE [People] SET [SomeColumn] = N'' WHERE [SomeColumn] IS NULL; ALTER TABLE [People] ALTER COLUMN [SomeColumn] nvarchar(450) NOT NULL; ALTER TABLE [People] ADD DEFAULT N'' FOR [SomeColumn]; @@ -1185,12 +1185,12 @@ public override async Task Alter_column_make_required_with_composite_index() AssertSql( """ DROP INDEX [IX_People_FirstName_LastName] ON [People]; -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'FirstName'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); UPDATE [People] SET [FirstName] = N'' WHERE [FirstName] IS NULL; ALTER TABLE [People] ALTER COLUMN [FirstName] nvarchar(450) NOT NULL; ALTER TABLE [People] ADD DEFAULT N'' FOR [FirstName]; @@ -1206,12 +1206,12 @@ public override async Task Alter_column_make_computed(bool? stored) AssertSql( $""" -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Sum'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] DROP COLUMN [Sum]; ALTER TABLE [People] ADD [Sum] AS [X] + [Y]{computedColumnTypeSql}; """); @@ -1223,12 +1223,12 @@ public override async Task Alter_column_change_computed() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Sum'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] DROP COLUMN [Sum]; ALTER TABLE [People] ADD [Sum] AS [X] - [Y]; """); @@ -1241,12 +1241,12 @@ public override async Task Alter_column_change_computed_recreates_indexes() AssertSql( """ DROP INDEX [IX_People_Sum] ON [People]; -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Sum'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] DROP COLUMN [Sum]; ALTER TABLE [People] ADD [Sum] AS [X] - [Y]; """, @@ -1262,12 +1262,12 @@ public override async Task Alter_column_change_computed_type() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Sum'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] DROP COLUMN [Sum]; ALTER TABLE [People] ADD [Sum] AS [X] + [Y] PERSISTED; """); @@ -1279,12 +1279,12 @@ public override async Task Alter_column_make_non_computed() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Sum'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] DROP COLUMN [Sum]; ALTER TABLE [People] ADD [Sum] int NOT NULL; """); @@ -1327,12 +1327,12 @@ public override async Task Alter_column_change_comment() AssertSql( """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -EXEC sp_dropextendedproperty 'MS_Description', 'SCHEMA', @defaultSchema, 'TABLE', N'People', 'COLUMN', N'Id'; -SET @description = N'Some comment2'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'People', 'COLUMN', N'Id'; +DECLARE @defaultSchema1 AS sysname; +SET @defaultSchema1 = SCHEMA_NAME(); +DECLARE @description1 AS sql_variant; +EXEC sp_dropextendedproperty 'MS_Description', 'SCHEMA', @defaultSchema1, 'TABLE', N'People', 'COLUMN', N'Id'; +SET @description1 = N'Some comment2'; +EXEC sp_addextendedproperty 'MS_Description', @description1, 'SCHEMA', @defaultSchema1, 'TABLE', N'People', 'COLUMN', N'Id'; """); } @@ -1343,10 +1343,10 @@ public override async Task Alter_column_remove_comment() AssertSql( """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -EXEC sp_dropextendedproperty 'MS_Description', 'SCHEMA', @defaultSchema, 'TABLE', N'People', 'COLUMN', N'Id'; +DECLARE @defaultSchema1 AS sysname; +SET @defaultSchema1 = SCHEMA_NAME(); +DECLARE @description1 AS sql_variant; +EXEC sp_dropextendedproperty 'MS_Description', 'SCHEMA', @defaultSchema1, 'TABLE', N'People', 'COLUMN', N'Id'; """); } @@ -1357,12 +1357,12 @@ public override async Task Alter_column_set_collation() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(max) COLLATE German_PhoneBook_CI_AS NULL; """); } @@ -1389,12 +1389,12 @@ await Test( AssertSql( """ DROP INDEX [IX_People_Name] ON [People]; -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) COLLATE German_PhoneBook_CI_AS NULL; CREATE INDEX [IX_People_Name] ON [People] ([Name]); """); @@ -1407,12 +1407,12 @@ public override async Task Alter_column_reset_collation() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(max) NULL; """); } @@ -1423,12 +1423,12 @@ public override async Task Convert_json_entities_to_regular_owned() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Entity]') AND [c].[name] = N'OwnedCollection'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Entity] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [Entity] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [Entity] DROP COLUMN [OwnedCollection]; """, // @@ -1501,12 +1501,12 @@ public override async Task Convert_regular_owned_entities_to_json() """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Entity]') AND [c].[name] = N'OwnedReference_Date'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Entity] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [Entity] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [Entity] DROP COLUMN [OwnedReference_Date]; """, // @@ -1542,12 +1542,12 @@ public override async Task Convert_string_column_to_a_json_column_containing_req AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Entity]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Entity] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [Entity] DROP CONSTRAINT [' + @var + '];'); UPDATE [Entity] SET [Name] = N'{}' WHERE [Name] IS NULL; ALTER TABLE [Entity] ALTER COLUMN [Name] nvarchar(max) NOT NULL; ALTER TABLE [Entity] ADD DEFAULT N'{}' FOR [Name]; @@ -1590,12 +1590,12 @@ await Test( AssertSql( """ DROP INDEX [IX_People_SomeColumn] ON [People]; -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'SomeColumn'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); UPDATE [People] SET [SomeColumn] = N'' WHERE [SomeColumn] IS NULL; ALTER TABLE [People] ALTER COLUMN [SomeColumn] nvarchar(450) NOT NULL; ALTER TABLE [People] ADD DEFAULT N'' FOR [SomeColumn]; @@ -1629,12 +1629,12 @@ await Test( AssertSql( """ ALTER TABLE [People] DROP INDEX [IX_People_Name]; -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(30) NULL; ALTER TABLE [People] ADD INDEX [IX_People_Name] NONCLUSTERED ([Name]); """); @@ -1662,12 +1662,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NULL; """); } @@ -1701,12 +1701,12 @@ await Test( AssertSql( """ DROP INDEX [IX_People_FirstName_LastName] ON [People]; -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(30) NULL; CREATE INDEX [IX_People_FirstName_LastName] ON [People] ([FirstName], [LastName]) INCLUDE ([Name]); """); @@ -1758,12 +1758,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'IdentityColumn'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [IdentityColumn] bigint NOT NULL; """); } @@ -1803,12 +1803,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ADD DEFAULT N'Doe' FOR [Name]; """); } @@ -1854,12 +1854,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'SomeProperty'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [SomeProperty] nvarchar(max) SPARSE NULL; """); } @@ -1870,12 +1870,12 @@ public override async Task Drop_column() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'SomeColumn'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] DROP COLUMN [SomeColumn]; """); } @@ -1890,12 +1890,12 @@ public override async Task Drop_column_primary_key() """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Id'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] DROP COLUMN [Id]; """); } @@ -1906,12 +1906,12 @@ public override async Task Drop_column_computed_and_non_computed_with_dependency AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Y'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] DROP COLUMN [Y]; """, // @@ -1932,12 +1932,12 @@ public override async Task Drop_json_columns_from_existing_table() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Entity]') AND [c].[name] = N'OwnedCollection'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Entity] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [Entity] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [Entity] DROP COLUMN [OwnedCollection]; """, // @@ -1982,12 +1982,12 @@ public override async Task Create_index() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'FirstName'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [FirstName] nvarchar(450) NULL; """, // @@ -2002,12 +2002,12 @@ public override async Task Create_index_unique() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'LastName'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [LastName] nvarchar(450) NULL; """, // @@ -2080,12 +2080,12 @@ public override async Task Create_index_with_filter() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NULL; """, // @@ -2117,12 +2117,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NULL; """, // @@ -2137,12 +2137,12 @@ public override async Task Create_unique_index_with_filter() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NULL; """, // @@ -2168,12 +2168,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'FirstName'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [FirstName] nvarchar(450) NULL; """, // @@ -2201,12 +2201,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'FirstName'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [FirstName] nvarchar(450) NULL; """, // @@ -2242,12 +2242,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NULL; """, // @@ -2285,12 +2285,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NULL; """, // @@ -2328,12 +2328,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NOT NULL; """, // @@ -2373,12 +2373,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NOT NULL; """, // @@ -2421,12 +2421,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NOT NULL; """, // @@ -2470,12 +2470,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NOT NULL; """, // @@ -2517,12 +2517,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NOT NULL; """, // @@ -2565,12 +2565,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NOT NULL; """, // @@ -2618,12 +2618,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NOT NULL; """, // @@ -2657,12 +2657,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NULL; """, // @@ -2697,12 +2697,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Name] nvarchar(450) NULL; """, // @@ -2773,12 +2773,12 @@ public override async Task Add_primary_key_string() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'SomeField'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [SomeField] nvarchar(450) NOT NULL; """, // @@ -2793,12 +2793,12 @@ public override async Task Add_primary_key_with_name() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'SomeField'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); UPDATE [People] SET [SomeField] = N'' WHERE [SomeField] IS NULL; ALTER TABLE [People] ALTER COLUMN [SomeField] nvarchar(450) NOT NULL; ALTER TABLE [People] ADD DEFAULT N'' FOR [SomeField]; @@ -2903,12 +2903,12 @@ public override async Task Drop_primary_key_string() """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'SomeField'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [SomeField] nvarchar(max) NOT NULL; """); } @@ -3255,12 +3255,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'SeqProp'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] DROP COLUMN [SeqProp]; """, // @@ -4437,8 +4437,8 @@ ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [RenamedCustomers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [RenamedCustomers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -4519,19 +4519,19 @@ ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -SET @description = N'for VIP only'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'RenamedCustomers', 'COLUMN', N'Discount'; +DECLARE @defaultSchema2 AS sysname; +SET @defaultSchema2 = SCHEMA_NAME(); +DECLARE @description2 AS sql_variant; +SET @description2 = N'for VIP only'; +EXEC sp_addextendedproperty 'MS_Description', @description2, 'SCHEMA', @defaultSchema2, 'TABLE', N'RenamedCustomers', 'COLUMN', N'Discount'; """, // """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -SET @description = N'for VIP only'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'HistoryTable', 'COLUMN', N'Discount'; +DECLARE @defaultSchema3 AS sysname; +SET @defaultSchema3 = SCHEMA_NAME(); +DECLARE @description3 AS sql_variant; +SET @description3 = N'for VIP only'; +EXEC sp_addextendedproperty 'MS_Description', @description3, 'SCHEMA', @defaultSchema3, 'TABLE', N'HistoryTable', 'COLUMN', N'Discount'; """, // """ @@ -4539,8 +4539,8 @@ ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [RenamedCustomers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [RenamedCustomers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -5356,48 +5356,48 @@ ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customers] DROP COLUMN [Name]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var3 sysname; +SELECT @var3 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'Name'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var1 + '];'); +IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); ALTER TABLE [HistoryTable] DROP COLUMN [Name]; """, // """ -DECLARE @var2 sysname; -SELECT @var2 = [d].[name] +DECLARE @var4 sysname; +SELECT @var4 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Number'); -IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); +IF @var4 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var4 + '];'); ALTER TABLE [Customers] DROP COLUMN [Number]; """, // """ -DECLARE @var3 sysname; -SELECT @var3 = [d].[name] +DECLARE @var5 sysname; +SELECT @var5 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'Number'); -IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); +IF @var5 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var5 + '];'); ALTER TABLE [HistoryTable] DROP COLUMN [Number]; """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -5454,12 +5454,12 @@ ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [Customers] DROP COLUMN [Name]; """, // @@ -5551,12 +5551,12 @@ ALTER TABLE [mySchema].[Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mySchema].[Customers]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [mySchema].[Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [mySchema].[Customers] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [mySchema].[Customers] DROP COLUMN [Name]; """, // @@ -5652,12 +5652,12 @@ ALTER TABLE [mySchema].[Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mySchema].[Customers]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [mySchema].[Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [mySchema].[Customers] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [mySchema].[Customers] DROP COLUMN [Name]; """, // @@ -5753,12 +5753,12 @@ ALTER TABLE [mySchema].[Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mySchema].[Customers]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [mySchema].[Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [mySchema].[Customers] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [mySchema].[Customers] DROP COLUMN [Name]; """, // @@ -5972,22 +5972,22 @@ ALTER TABLE [Customer] DROP PERIOD FOR SYSTEM_TIME """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customer]') AND [c].[name] = N'PeriodEnd'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customer] DROP COLUMN [PeriodEnd]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customer]') AND [c].[name] = N'PeriodStart'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var1 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customer] DROP COLUMN [PeriodStart]; """, // @@ -6051,22 +6051,22 @@ ALTER TABLE [Customer] DROP PERIOD FOR SYSTEM_TIME """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customer]') AND [c].[name] = N'PeriodEnd'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customer] DROP COLUMN [PeriodEnd]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customer]') AND [c].[name] = N'PeriodStart'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var1 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customer] DROP COLUMN [PeriodStart]; """, // @@ -6926,11 +6926,11 @@ await Test( AssertSql( """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -SET @description = N'My comment'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'Customers', 'COLUMN', N'End'; +DECLARE @defaultSchema1 AS sysname; +SET @defaultSchema1 = SCHEMA_NAME(); +DECLARE @description1 AS sql_variant; +SET @description1 = N'My comment'; +EXEC sp_addextendedproperty 'MS_Description', @description1, 'SCHEMA', @defaultSchema1, 'TABLE', N'Customers', 'COLUMN', N'End'; """); } @@ -7050,32 +7050,32 @@ ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customer]') AND [c].[name] = N'IsVip'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var0 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var2 + '];'); UPDATE [Customer] SET [IsVip] = CAST(0 AS bit) WHERE [IsVip] IS NULL; ALTER TABLE [Customer] ALTER COLUMN [IsVip] bit NOT NULL; ALTER TABLE [Customer] ADD DEFAULT CAST(0 AS bit) FOR [IsVip]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var3 sysname; +SELECT @var3 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'IsVip'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var1 + '];'); +IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); UPDATE [HistoryTable] SET [IsVip] = CAST(0 AS bit) WHERE [IsVip] IS NULL; ALTER TABLE [HistoryTable] ALTER COLUMN [IsVip] bit NOT NULL; ALTER TABLE [HistoryTable] ADD DEFAULT CAST(0 AS bit) FOR [IsVip]; """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -7196,8 +7196,8 @@ ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -7260,8 +7260,8 @@ ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -7315,28 +7315,28 @@ ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customer]') AND [c].[name] = N'IdPlusFive'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var0 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customer] DROP COLUMN [IdPlusFive]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var3 sysname; +SELECT @var3 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'IdPlusFive'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var1 + '];'); +IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); ALTER TABLE [HistoryTable] DROP COLUMN [IdPlusFive]; """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -7506,28 +7506,28 @@ ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customer]') AND [c].[name] = N'Number'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var0 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customer] DROP COLUMN [Number]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var3 sysname; +SELECT @var3 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'Number'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var1 + '];'); +IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); ALTER TABLE [HistoryTable] DROP COLUMN [Number]; """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -7652,8 +7652,8 @@ IF EXISTS (SELECT 1 FROM [sys].[tables] [t] INNER JOIN [sys].[partitions] [p] ON """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -7793,28 +7793,28 @@ IF EXISTS (SELECT 1 FROM [sys].[tables] [t] INNER JOIN [sys].[partitions] [p] ON """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customer]') AND [c].[name] = N'MyColumn'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var0 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customer] ALTER COLUMN [MyColumn] int SPARSE NULL; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var3 sysname; +SELECT @var3 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'MyColumn'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var1 + '];'); +IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); ALTER TABLE [HistoryTable] ALTER COLUMN [MyColumn] int SPARSE NULL; """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customer] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -7874,12 +7874,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customer]') AND [c].[name] = N'MyColumn'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customer] ALTER COLUMN [MyColumn] int NULL; """); } @@ -8017,13 +8017,13 @@ [Name] nvarchar(max) NULL, CONSTRAINT [PK_Customer] PRIMARY KEY ([Id]), PERIOD FOR SYSTEM_TIME([SystemTimeStart], [SystemTimeEnd]) ) WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + N'].[CustomerHistory]))'); -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -SET @description = N'Table comment'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'Customer'; -SET @description = N'Column comment'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'Customer', 'COLUMN', N'Name'; +DECLARE @defaultSchema1 AS sysname; +SET @defaultSchema1 = SCHEMA_NAME(); +DECLARE @description1 AS sql_variant; +SET @description1 = N'Table comment'; +EXEC sp_addextendedproperty 'MS_Description', @description1, 'SCHEMA', @defaultSchema1, 'TABLE', N'Customer'; +SET @description1 = N'Column comment'; +EXEC sp_addextendedproperty 'MS_Description', @description1, 'SCHEMA', @defaultSchema1, 'TABLE', N'Customer', 'COLUMN', N'Name'; """); } @@ -8077,18 +8077,18 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customer]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customer] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customer] ALTER COLUMN [Name] nvarchar(450) NULL; -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -SET @description = N'Column comment'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'Customer', 'COLUMN', N'Name'; +DECLARE @defaultSchema2 AS sysname; +SET @defaultSchema2 = SCHEMA_NAME(); +DECLARE @description2 AS sql_variant; +SET @description2 = N'Column comment'; +EXEC sp_addextendedproperty 'MS_Description', @description2, 'SCHEMA', @defaultSchema2, 'TABLE', N'Customer', 'COLUMN', N'Name'; """, // """ @@ -8174,21 +8174,21 @@ await Test( AssertSql( """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -EXEC sp_dropextendedproperty 'MS_Description', 'SCHEMA', @defaultSchema, 'TABLE', N'Customer'; -SET @description = N'Modified table comment'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'Customer'; +DECLARE @defaultSchema2 AS sysname; +SET @defaultSchema2 = SCHEMA_NAME(); +DECLARE @description2 AS sql_variant; +EXEC sp_dropextendedproperty 'MS_Description', 'SCHEMA', @defaultSchema2, 'TABLE', N'Customer'; +SET @description2 = N'Modified table comment'; +EXEC sp_addextendedproperty 'MS_Description', @description2, 'SCHEMA', @defaultSchema2, 'TABLE', N'Customer'; """, // """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -EXEC sp_dropextendedproperty 'MS_Description', 'SCHEMA', @defaultSchema, 'TABLE', N'Customer', 'COLUMN', N'Name'; -SET @description = N'Modified column comment'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'Customer', 'COLUMN', N'Name'; +DECLARE @defaultSchema3 AS sysname; +SET @defaultSchema3 = SCHEMA_NAME(); +DECLARE @description3 AS sql_variant; +EXEC sp_dropextendedproperty 'MS_Description', 'SCHEMA', @defaultSchema3, 'TABLE', N'Customer', 'COLUMN', N'Name'; +SET @description3 = N'Modified column comment'; +EXEC sp_addextendedproperty 'MS_Description', @description3, 'SCHEMA', @defaultSchema3, 'TABLE', N'Customer', 'COLUMN', N'Name'; """); } @@ -8244,12 +8244,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customers] ALTER COLUMN [Name] nvarchar(450) NULL; """, // @@ -8316,12 +8316,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customers] ALTER COLUMN [Name] nvarchar(450) NULL; """, // @@ -8804,22 +8804,22 @@ ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Number'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customers] DROP COLUMN [Number]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var3 sysname; +SELECT @var3 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'Number'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var1 + '];'); +IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); ALTER TABLE [HistoryTable] DROP COLUMN [Number]; """, // @@ -8840,8 +8840,8 @@ FROM [sys].[default_constraints] [d] """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -8916,22 +8916,22 @@ ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Number'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customers] DROP COLUMN [Number]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var3 sysname; +SELECT @var3 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'Number'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var1 + '];'); +IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); ALTER TABLE [HistoryTable] DROP COLUMN [Number]; """, // @@ -8952,8 +8952,8 @@ FROM [sys].[default_constraints] [d] """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [ModifiedCustomers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [ModifiedCustomers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -9024,22 +9024,22 @@ ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Number'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customers] DROP COLUMN [Number]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var3 sysname; +SELECT @var3 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'Number'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var1 + '];'); +IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); ALTER TABLE [HistoryTable] DROP COLUMN [Number]; """, // @@ -9056,8 +9056,8 @@ FROM [sys].[default_constraints] [d] """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[ModifiedHistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[ModifiedHistoryTable]))') """); } @@ -9119,22 +9119,22 @@ ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Number'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customers] DROP COLUMN [Number]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var3 sysname; +SELECT @var3 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'Number'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var1 + '];'); +IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); ALTER TABLE [HistoryTable] DROP COLUMN [Number]; """, // @@ -9147,8 +9147,8 @@ FROM [sys].[default_constraints] [d] """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -9211,44 +9211,44 @@ ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Number'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customers] DROP COLUMN [Number]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var3 sysname; +SELECT @var3 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'Number'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var1 + '];'); +IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); ALTER TABLE [HistoryTable] DROP COLUMN [Number]; """, // """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -SET @description = N'My comment'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'Customers', 'COLUMN', N'Name'; +DECLARE @defaultSchema4 AS sysname; +SET @defaultSchema4 = SCHEMA_NAME(); +DECLARE @description4 AS sql_variant; +SET @description4 = N'My comment'; +EXEC sp_addextendedproperty 'MS_Description', @description4, 'SCHEMA', @defaultSchema4, 'TABLE', N'Customers', 'COLUMN', N'Name'; """, // """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -SET @description = N'My comment'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'HistoryTable', 'COLUMN', N'Name'; +DECLARE @defaultSchema5 AS sysname; +SET @defaultSchema5 = SCHEMA_NAME(); +DECLARE @description5 AS sql_variant; +SET @description5 = N'My comment'; +EXEC sp_addextendedproperty 'MS_Description', @description5, 'SCHEMA', @defaultSchema5, 'TABLE', N'HistoryTable', 'COLUMN', N'Name'; """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -9314,11 +9314,11 @@ await Test( """, // """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -SET @description = N'My comment'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'Customers', 'COLUMN', N'End'; +DECLARE @defaultSchema1 AS sysname; +SET @defaultSchema1 = SCHEMA_NAME(); +DECLARE @description1 AS sql_variant; +SET @description1 = N'My comment'; +EXEC sp_addextendedproperty 'MS_Description', @description1, 'SCHEMA', @defaultSchema1, 'TABLE', N'Customers', 'COLUMN', N'End'; """); } @@ -9385,22 +9385,22 @@ ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'DateOfBirth'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customers] DROP COLUMN [DateOfBirth]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var3 sysname; +SELECT @var3 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'DateOfBirth'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var1 + '];'); +IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); ALTER TABLE [HistoryTable] DROP COLUMN [DateOfBirth]; """, // @@ -9413,24 +9413,24 @@ FROM [sys].[default_constraints] [d] """, // """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -SET @description = N'My comment'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'Customers', 'COLUMN', N'End'; +DECLARE @defaultSchema4 AS sysname; +SET @defaultSchema4 = SCHEMA_NAME(); +DECLARE @description4 AS sql_variant; +SET @description4 = N'My comment'; +EXEC sp_addextendedproperty 'MS_Description', @description4, 'SCHEMA', @defaultSchema4, 'TABLE', N'Customers', 'COLUMN', N'End'; """, // """ -DECLARE @defaultSchema AS sysname; -SET @defaultSchema = SCHEMA_NAME(); -DECLARE @description AS sql_variant; -SET @description = N'My comment'; -EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'HistoryTable', 'COLUMN', N'End'; +DECLARE @defaultSchema5 AS sysname; +SET @defaultSchema5 = SCHEMA_NAME(); +DECLARE @description5 AS sql_variant; +SET @description5 = N'My comment'; +EXEC sp_addextendedproperty 'MS_Description', @description5, 'SCHEMA', @defaultSchema5, 'TABLE', N'HistoryTable', 'COLUMN', N'End'; """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[HistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[HistoryTable]))') """); } @@ -9797,12 +9797,12 @@ await Test( AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Number'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customers] DROP COLUMN [Number]; """, // @@ -9968,22 +9968,22 @@ ALTER TABLE [Customers] DROP PERIOD FOR SYSTEM_TIME """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'End'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customers] DROP COLUMN [End]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Start'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customers] DROP COLUMN [Start]; """, // @@ -10050,42 +10050,42 @@ ALTER TABLE [Customers] DROP PERIOD FOR SYSTEM_TIME """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'End'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customers] DROP COLUMN [End]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Number'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customers] DROP COLUMN [Number]; """, // """ -DECLARE @var2 sysname; -SELECT @var2 = [d].[name] +DECLARE @var3 sysname; +SELECT @var3 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[HistoryTable]') AND [c].[name] = N'Number'); -IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var2 + '];'); +IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [HistoryTable] DROP CONSTRAINT [' + @var3 + '];'); ALTER TABLE [HistoryTable] DROP COLUMN [Number]; """, // """ -DECLARE @var3 sysname; -SELECT @var3 = [d].[name] +DECLARE @var4 sysname; +SELECT @var4 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Start'); -IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var3 + '];'); +IF @var4 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var4 + '];'); ALTER TABLE [Customers] DROP COLUMN [Start]; """, // @@ -10150,22 +10150,22 @@ ALTER TABLE [Customers] DROP PERIOD FOR SYSTEM_TIME """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'End'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customers] DROP COLUMN [End]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Start'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customers] DROP COLUMN [Start]; """, // @@ -10324,12 +10324,12 @@ await Test( """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Number'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customers] DROP COLUMN [Number]; """, // @@ -10519,22 +10519,22 @@ ALTER TABLE [Customers] DROP PERIOD FOR SYSTEM_TIME """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'End'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customers] DROP COLUMN [End]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Start'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customers] DROP COLUMN [Start]; """, // @@ -10641,8 +10641,8 @@ ALTER TABLE [Customers] SET (SYSTEM_VERSIONING = OFF) """, // """ -DECLARE @historyTableSchema sysname = SCHEMA_NAME() -EXEC(N'ALTER TABLE [NewCustomers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema + '].[NewHistoryTable]))') +DECLARE @historyTableSchema1 sysname = SCHEMA_NAME() +EXEC(N'ALTER TABLE [NewCustomers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [' + @historyTableSchema1 + '].[NewHistoryTable]))') """); } @@ -10724,22 +10724,22 @@ ALTER TABLE [Customers] DROP PERIOD FOR SYSTEM_TIME """, // """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'End'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); ALTER TABLE [Customers] DROP COLUMN [End]; """, // """ -DECLARE @var1 sysname; -SELECT @var1 = [d].[name] +DECLARE @var2 sysname; +SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Start'); -IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];'); +IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Customers] DROP COLUMN [Start]; """, // diff --git a/test/EFCore.SqlServer.FunctionalTests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs b/test/EFCore.SqlServer.FunctionalTests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs index 9e8f89ad5f6..0b4f87a279e 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs @@ -227,12 +227,12 @@ public override void AlterColumnOperation_without_column_type() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'LuckyNumber'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [LuckyNumber] int NOT NULL; """); } @@ -262,12 +262,12 @@ public virtual void AlterColumnOperation_with_identity_legacy() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Id'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [People] ALTER COLUMN [Id] int NOT NULL; """); } @@ -296,12 +296,12 @@ public virtual void AlterColumnOperation_with_index_no_oldColumn() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Person]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Person] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [Person] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [Person] ALTER COLUMN [Name] nvarchar(30) NULL; """); } @@ -336,12 +336,12 @@ public virtual void AlterColumnOperation_with_added_index() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Person]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Person] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [Person] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [Person] ALTER COLUMN [Name] nvarchar(30) NULL; GO @@ -378,12 +378,12 @@ public virtual void AlterColumnOperation_with_added_index_no_oldType() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Person]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Person] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [Person] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [Person] ALTER COLUMN [Name] nvarchar(450) NULL; GO @@ -411,12 +411,12 @@ public virtual void AlterColumnOperation_identity_legacy() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Person]') AND [c].[name] = N'Id'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Person] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [Person] DROP CONSTRAINT [' + @var + '];'); ALTER TABLE [Person] ALTER COLUMN [Id] bigint NOT NULL; """); } @@ -595,8 +595,8 @@ public virtual void AlterDatabaseOperation_collation_to_default() """ BEGIN DECLARE @db_name nvarchar(max) = DB_NAME(); -DECLARE @defaultCollation nvarchar(max) = CAST(SERVERPROPERTY('Collation') AS nvarchar(max)); -EXEC(N'ALTER DATABASE [' + @db_name + '] COLLATE ' + @defaultCollation + N';'); +DECLARE @defaultCollation1 nvarchar(max) = CAST(SERVERPROPERTY('Collation') AS nvarchar(max)); +EXEC(N'ALTER DATABASE [' + @db_name + '] COLLATE ' + @defaultCollation1 + N';'); END """); @@ -1264,12 +1264,12 @@ public virtual void AlterColumn_make_required_with_idempotent() AssertSql( """ -DECLARE @var0 sysname; -SELECT @var0 = [d].[name] +DECLARE @var sysname; +SELECT @var = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Person]') AND [c].[name] = N'Name'); -IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Person] DROP CONSTRAINT [' + @var0 + '];'); +IF @var IS NOT NULL EXEC(N'ALTER TABLE [Person] DROP CONSTRAINT [' + @var + '];'); EXEC(N'UPDATE [Person] SET [Name] = N'''' WHERE [Name] IS NULL'); ALTER TABLE [Person] ALTER COLUMN [Name] nvarchar(max) NOT NULL; ALTER TABLE [Person] ADD DEFAULT N'' FOR [Name]; diff --git a/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestRelationalCommandBuilderFactory.cs b/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestRelationalCommandBuilderFactory.cs index 7d682aeb67c..754e1670159 100644 --- a/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestRelationalCommandBuilderFactory.cs +++ b/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestRelationalCommandBuilderFactory.cs @@ -54,6 +54,13 @@ public IRelationalCommandBuilder Append(string value) return this; } + public IRelationalCommandBuilder Append(FormattableString value) + { + Instance.Append(value); + + return this; + } + public IRelationalCommandBuilder AppendLine() { Instance.AppendLine();