Mysql
SQL 語法錯誤;檢查與您的 MySQL 伺服器版本相對應的手冊
我在創建表時將 MariaDB 10.4.17 數據庫恢復到 Amazon aurora MySQL 5.6,它向我顯示此錯誤
ERROR 1064 (42000) at line 25 in file: 'name.sql': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sha2(uuid(),256), `InsertTs` timestamp NOT NULL DEFAULT current_timestamp(), ' at line 17 Query OK, 0 rows affected (0.001 sec)
錯誤在’sha2(uuid(),256)‘行中
CREATE TABLE `User` ( `ID` bigint(20) NOT NULL AUTO_INCREMENT, `Version` bigint(20) DEFAULT 0, `FirstName` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `LastName` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `UserName` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `Password` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `PasswordSalt` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `PasswordExpires` datetime DEFAULT NULL, `ForcePasswordChange` bit(1) DEFAULT b'0', `Email` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `Phone` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `NickName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `TextNumber` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `IsValid` bit(1) DEFAULT b'0', `IsMigrated` bit(1) DEFAULT b'1', `UUID` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT sha2(uuid(),256), `InsertTs` timestamp NOT NULL DEFAULT current_timestamp(), `UpdateTs` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), `PIN` bigint(20) DEFAULT NULL, `LatestInviteStatus` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `LatestInviteDate` date DEFAULT NULL, `LatestInviteUUID` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `uk_User_UserName_UNIQUE` (`UserName`), UNIQUE KEY `uk_User_UUID_UNIQUE` (`UUID`), KEY `idxPIN` (`PIN`) ) ENGINE=InnoDB AUTO_INCREMENT=90184 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
我無法弄清楚它在工作台上是什麼,它說 sha2 在這個位置無效
您的 CREATE TABLE 將失敗,因為行中沒有
PIN
提到任何列KEY
idxPIN(
PIN)
。MySQL 5.6 不允許將表達式作為預設值。使用觸發器:
CREATE TABLE `Customer` ( `ID` bigint(20) NOT NULL AUTO_INCREMENT, `Version` bigint(20) DEFAULT 0, `FirstName` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `LastName` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `UserName` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `Password` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `PasswordSalt` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `PasswordExpires` datetime DEFAULT NULL, `ForcePasswordChange` bit(1) DEFAULT b'0', `Email` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `Phone` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `NickName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `TextNumber` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `IsValid` bit(1) DEFAULT b'0', `IsMigrated` bit(1) DEFAULT b'1', `UUID` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `InsertTs` timestamp NOT NULL DEFAULT current_timestamp(), `UpdateTs` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`ID`), UNIQUE KEY `uk_User_UserName_UNIQUE` (`UserName`), UNIQUE KEY `uk_User_UUID_UNIQUE` (`UUID`), -- ------------- `PIN` INT, -- ------------- KEY `idxPIN` (`PIN`) ) ENGINE=InnoDB AUTO_INCREMENT=90184 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TRIGGER set_uuid BEFORE INSERT ON Customer FOR EACH ROW SET NEW.UUID = COALESCE(NEW.UUID, sha2(uuid(),256));