所以我試圖將一個表從 MySQL 遷移到 MSSQL ( sql server migration assistant MySQL),但是我收到了這個錯誤:
Migrating data...
Analyzing metadata...
Preparing table testreportingdebug.testcase...
Preparing data migration package...
Starting data migration Engine
Starting data migration...
The data migration engine is migrating table '`testreportingdebug`.`testcase`': > [SwMetrics].[testreportingdebug].[testcase], 8855 rows total
Violation of UNIQUE KEY constraint 'testcase$Unique'. Cannot insert duplicate key in object 'testreportingdebug.testcase'. The duplicate key value is (<NULL>, <NULL>).
Errors: Violation of UNIQUE KEY constraint 'testcase$Unique'. Cannot insert duplicate key in object 'testreportingdebug.testcase'. The duplicate key value is (<NULL>, <NULL>).
Completing migration of table `testreportingdebug`.`testcase`...
Migration complete for table '`testreportingdebug`.`testcase`': > [SwMetrics].[testreportingdebug].[testcase], 0 rows migrated (Elapsed Time = 00:00:00:01:352).
Data migration operation has finished.
0 table(s) successfully migrated.
0 table(s) partially migrated.
1 table(s) failed to migrate.
我剛剛從我的表中復制了三行,這就是它們的樣子:
'1', 'Pump# TimeToService', NULL, NULL, 'A general test case comment ...', '0'
'2', 'Config.SlaveMinimumReplyDelay', NULL, NULL, NULL, '0'
'3', 'Config.RESERVED', NULL, NULL, NULL, '0'
如果您想知道 MySQL 表中的冒號是如何設定的,請看這里:

是因為right, left and comment可以為空嗎?
表的 DDL
CREATE TABLE `testcase` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`TestCaseName` varchar(150) DEFAULT NULL,
`Left` int(11) DEFAULT NULL,
`Right` int(11) DEFAULT NULL,
`Comment` text,
`Hidden` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `Unique` (`Left`,`Right`)
) ENGINE=InnoDB AUTO_INCREMENT=10580 DEFAULT CHARSET=utf8
uj5u.com熱心網友回復:
不得不洗掉 Unique 部分,因為它們只是 NULL。
ALTER TABLE `testreportingdebug`.`testcase`
DROP INDEX `Unique`;
uj5u.com熱心網友回復:
如果您想要 MySQL 表的 SQL Server 中的嚴格等價物,您必須像這樣創建它:
CREATE TABLE testcase (
id int NOT NULL IDENTITY PRIMARY KEY,
TestCaseName varchar(150),
[Left] int,
[Right] int,
Comment VARCHAR(max),
[Hidden] tinyint DEFAULT 0,
);
CREATE UNIQUE INDEX X_testcase_right_left
ON testcase ([Left], [Right])
WHERE [Left] IS NOT NULL
AND [Right] IS NOT NULL;
順便說一句,列名“Right”、“left”、“hidden”是 SQL / MS SQL Server 保留字,不應在任何時候用于 SQL 識別符號(表名、列名、proc 名......)
完整串列可在此處獲取
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/422533.html
標籤:
上一篇:在python中使用connectorx連接MSSQLServer
下一篇:更改sql視圖的排序規則
