Skip to content

Commit 2d72d1f

Browse files
[6.x] Fix for dropping columns when using MSSQL as database (#39905)
1 parent 5e56518 commit 2d72d1f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function compileDropDefaultConstraint(Blueprint $blueprint, Fluent $comma
212212

213213
$sql = "DECLARE @sql NVARCHAR(MAX) = '';";
214214
$sql .= "SELECT @sql += 'ALTER TABLE [dbo].[{$tableName}] DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' ";
215-
$sql .= 'FROM SYS.COLUMNS ';
215+
$sql .= 'FROM sys.columns ';
216216
$sql .= "WHERE [object_id] = OBJECT_ID('[dbo].[{$tableName}]') AND [name] in ({$columns}) AND [default_object_id] <> 0;";
217217
$sql .= 'EXEC(@sql)';
218218

tests/Database/DatabaseSqlServerSchemaGrammarTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function testDropColumnDropsCreatesSqlToDropDefaultConstraints()
122122
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
123123

124124
$this->assertCount(1, $statements);
125-
$this->assertEquals("DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE [dbo].[foo] DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM SYS.COLUMNS WHERE [object_id] = OBJECT_ID('[dbo].[foo]') AND [name] in ('bar') AND [default_object_id] <> 0;EXEC(@sql);alter table \"foo\" drop column \"bar\"", $statements[0]);
125+
$this->assertEquals("DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE [dbo].[foo] DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID('[dbo].[foo]') AND [name] in ('bar') AND [default_object_id] <> 0;EXEC(@sql);alter table \"foo\" drop column \"bar\"", $statements[0]);
126126
}
127127

128128
public function testDropPrimary()

0 commit comments

Comments
 (0)