2014-01-30 27 views
-1

我一遍又一遍地看了這個,並且正在看我是否能夠得到額外的一組眼睛。我試圖運行一個創建表查詢,但我似乎無法得到它的工作。我得到的錯誤是這個查詢中的錯誤在哪裏

#1064 - 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 '`1`, `id_shop` int(11) NOT NULL DEFAULT `1`, `id_lang` int(10) NOT NULL DEFAUL' at line 4 

這裏我試圖運行

CREATE TABLE IF NOT EXISTS `PREFIX_quote` (
`id_quote` int(10) NOT NULL AUTO_INCREMENT, 
`reference` varchar(9) DEFAULT NULL, 
`id_shop_group` int(11) NOT NULL DEFAULT `1`, 
`id_shop` int(11) NOT NULL DEFAULT `1`, 
`id_lang` int(10) NOT NULL DEFAULT `1`, 
`id_customer` int(10) NOT NULL, 
`total_discounts` decimal(17,2) NOT NULL DEFAULT `0.00`, 
`total_products` decimal(17,2) NOT NULL DEFAULT `0.00`, 
`total_product_wt` decimal(17,2) NOT NULL DEFAULT `0.00`, 
`total_shipping` decimal(17,2) NOT NULL DEFAULT `0.00`, 
`quote_number` int(10) NOT NULL DEFAULT `0`, 
`quote_date` datetime NOT NULL, 
`valid` int(1) NOT NULL DEFAULT `1`, 
`id_employee` int(11) NOT NULL, 
`date_add` datetime NOT NULL, 
`date_upd` datetime NOT NULL, 
PRIMARY KEY (`id_quote`), 
KEY `id_customer` (`id_customer`), 
KEY `id_employee` (`id_employee`)); 
+2

我相信這是對話題,因爲有一個特定的錯誤信息和代碼示例。這不是一般的「爲我調試我的代碼」的問題。 – JasonMArcher

回答

4

串門整數反引號中的查詢。見the fiddle

CREATE TABLE IF NOT EXISTS `PREFIX_quote` (
`id_quote` int(10) NOT NULL AUTO_INCREMENT, 
`reference` varchar(9) DEFAULT NULL, 
`id_shop_group` int(11) NOT NULL DEFAULT 1, 
`id_shop` int(11) NOT NULL DEFAULT 1, 
`id_lang` int(10) NOT NULL DEFAULT 1, 
`id_customer` int(10) NOT NULL, 
`total_discounts` decimal(17,2) NOT NULL DEFAULT 0.00, 
`total_products` decimal(17,2) NOT NULL DEFAULT 0.00, 
`total_product_wt` decimal(17,2) NOT NULL DEFAULT 0.00, 
`total_shipping` decimal(17,2) NOT NULL DEFAULT 0.00, 
`quote_number` int(10) NOT NULL DEFAULT 0, 
`quote_date` datetime NOT NULL, 
`valid` int(1) NOT NULL DEFAULT 1, 
`id_employee` int(11) NOT NULL, 
`date_add` datetime NOT NULL, 
`date_upd` datetime NOT NULL, 
PRIMARY KEY (`id_quote`), 
KEY `id_customer` (`id_customer`), 
KEY `id_employee` (`id_employee`)); 
2

您的價值在反推:`1`,這是不正確的。這是用引號引起來的,或者因爲它是一個數字,所以不加引號。

`id_shop_group` int(11) NOT NULL DEFAULT 1, 

請務必爲您的所有領域做到這一點。

4

反引號(`)用於在MySQL中引用identifiers,以便保留字或特殊字符可以出現在它們中。它們通常用來包圍列名,你在做這,即使它通常是不必要的,但不是:從您的默認值刪除反引號:

CREATE TABLE IF NOT EXISTS `PREFIX_quote` (
`id_quote` int(10) NOT NULL AUTO_INCREMENT, 
`reference` varchar(9) DEFAULT NULL, 
`id_shop_group` int(11) NOT NULL DEFAULT 1, 
...