2017-02-12 8 views
0

Ich habe versucht, folgende Abfrage auf meinem SQL-Server laufen zu Ihrem MariaDB Server entspricht:# 1064 - Sie haben einen Fehler in Ihrer SQL-Syntax; Sie in die Bedienungsanleitung

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 
); 

Ich habe bereits Marken und Kategorien Tabellen auf meiner e_store Datenbank.

Aber ich bekam die folgenden Fehler:

#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

Welche Version von db verwenden Sie ..? – scaisEdge

+0

Ich verwende XAMPP, 10.1.19-MariaDB – User57

+0

SELECT VERSION; – Strawberry

Antwort

1

Sie einfache Anführungszeichen in Ihrem Index Definitionen gegeben hat anstelle von Backticks

Try this:

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

das ist nicht die Lösung, die ich denke, denn ich habe bereits mit dem überprüft ... nichts kam heraus. ..Mit dem gleichen Fehler bekomme ich – User57

0

Ich glaube, Sie Fehler bekommen für JSON-Datentyp.

Für Mysql 5.7 können Sie Hilfe von unten Link erhalten.

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

können Sie überprüfen vesrion unter Abfrage verwenden.

select version() as 'mysql version' 
+0

@scaisEdge die [JSON * Tabelle * Typ] (https://mariadb.com/kb/en/mariadb/connect-json-table-type/) in MariaDB 10.0.16 ist völlig unabhängig von JSON-Spalten. –

1

"JSON" wird im Server analysiert. JSON ist einer der Punkte der Divergenz.

MySQL 5.7 führte den JSON Datentyp ein, der Ihrer Syntax entspricht.

MariaDB 10.0.16 führte eine ENGINE=CONNECT table_type=JSON ein, die nicht mit Ihrer versuchten Syntax übereinstimmt.

Verwandte Themen