2017-02-12 40 views
0

我想我的SQL服務器上運行下面的查詢手冊:我已經在我的e_store數據庫品牌和類別表#1064 - 您的SQL語法有錯誤;檢查對應於您MariaDB的服務器

CREATE TABLE `e_store`.`products`(
    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT , 
    `name` VARCHAR(250) NOT NULL , 
    `brand_id` INT UNSIGNED NOT NULL , 
    `category_id` INT UNSIGNED NOT NULL , 
    `attributes` JSON NOT NULL , 
    PRIMARY KEY(`id`) , 
    INDEX `CATEGORY_ID`(`category_id` ASC) , 
    INDEX `BRAND_ID`(`brand_id` ASC) , 
    CONSTRAINT `brand_id` FOREIGN KEY(`brand_id`) REFERENCES `e_store`.`brands`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE , 
    CONSTRAINT `category_id` FOREIGN KEY(`category_id`) REFERENCES `e_store`.`categories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE 
); 

,但我得到了以下錯誤:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'JSON NOT NULL , 
    PRIMARY KEY(`id`) , 
    INDEX `CATEGORY_ID`('category_id' ' at line 6 
+0

你正在使用哪個版本的db ..? – scaisEdge

+0

我正在使用XAMPP,10.1.19-MariaDB – User57

+0

SELECT VERSION; – Strawberry

回答

1

你已經在你的索引定義,而不是反引號給予單引號

試試這個:

CREATE TABLE `e_store`.`products`(
    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT , 
    `name` VARCHAR(250) NOT NULL , 
    `brand_id` INT UNSIGNED NOT NULL , 
    `category_id` INT UNSIGNED NOT NULL , 
    `attributes` JSON NOT NULL , 
    PRIMARY KEY(`id`) , 
    INDEX `CATEGORY_ID`(`category_id` ASC) , -- Changed single quotes to backticks 
    INDEX `BRAND_ID`(`brand_id` ASC) , -- Changed single quotes to backticks 
    CONSTRAINT `brand_id` FOREIGN KEY(`brand_id`) REFERENCES `e_store`.`brands`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE , 
    CONSTRAINT `category_id` FOREIGN KEY(`category_id`) REFERENCES `e_store`.`categories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE 
); 
+0

這不是我猜想的解決方案,因爲我已經檢查過了......沒有出來。 ..means同樣的錯誤我得到 – User57

0

我覺得你得到錯誤爲JSON數據類型。

對於Mysql 5.7,您可以從下面的鏈接獲得幫助。

https://dev.mysql.com/doc/refman/5.7/en/json.html

您可以檢查vesrion使用下面的查詢。

select version() as 'mysql version' 
+0

@scaisEdge MariaDB 10.0.16中的[JSON * table * type](https://mariadb.com/kb/en/mariadb/connect-json-table-type/)是與JSON列完全無關。 –

1

JSON」在服務器中被解析。 JSON是分歧點之一。

MySQL 5.7引入了JSON數據類型,它符合您的語法。

MariaDB 10.0.16引入了一個ENGINE=CONNECT table_type=JSON,它與您嘗試的語法不匹配。

相關問題