From e9b62f7880d4467e555ebd3cf6626f93d1e7f771 Mon Sep 17 00:00:00 2001 From: Alexander Zhuravlev Date: Sat, 31 Mar 2018 01:09:42 +1300 Subject: [PATCH] MsSQL fixes and CS fix --- lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | 1 + lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 07e484472c8..e3ef90fb9a7 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -2080,6 +2080,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) foreach ($diff->changedIndexes as $index) { if ($index->isPrimary()) { $sql[] = $this->getDropPrimaryKeySQL($tableName); + continue; } diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 812bf80a36e..3e63d1706e6 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1619,4 +1619,18 @@ private function generateIdentifierName($identifier) return strtoupper(dechex(crc32($identifier->getName()))); } + + protected function getDropPrimaryKeySQL(string $table) : string + { + return " +DECLARE @table NVARCHAR(512), @sql NVARCHAR(MAX); +SELECT @table = N'{$table}'; +SELECT @sql = 'ALTER TABLE ' + @table + ' DROP CONSTRAINT + name + ';' + FROM sys.key_constraints + WHERE [type] = 'PK' + AND [parent_object_id] = OBJECT_ID(@table); + +EXEC sp_executeSQL @sql;"; + } + }