2012-03-14 99 views
0

我想創建一個產品表上運行下面的SQL查詢:SQL產品表創建 - 語法錯誤

CREATE TABLE ‘products’ (
    ‘id’ INT NOT NULL AUTO_INCREMENT , 
    ‘name’ VARCHAR(255) NOT NULL , 
    ‘shortdesc’ VARCHAR(255) NOT NULL , 
    ‘longdesc’ TEXT NOT NULL , 
    ‘thumbnail’ VARCHAR(255) NOT NULL , 
    ‘image’ VARCHAR(255) NOT NULL , 
    ‘sizes’ ENUM(‘s’, ‘m’, ‘l’, ‘xl’) NOT NULL , 
    ‘colors’ ENUM(‘red’, ‘blue’, ‘green’, ‘brown’, ‘white’, ‘black’) NOT NULL , 
    ‘grouping’ VARCHAR(16) NOT NULL , 
    ‘status’ ENUM(‘active’, ‘inactive’) NOT NULL , 
    ‘category_id’ INT NOT NULL , 
    ‘featured’ ENUM (‘true’, ‘false’) NOT NULL, 
    ‘price’ FLOAT(4, 2) NOT NULL, 
PRIMARY KEY (‘id’) 
) TYPE = MYISAM ; 

但出現此錯誤:

#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 '‘s’, ‘m’, ‘l’, ‘xl’) NOT NULL , ‘colors’ ENUM(‘red’, ' at line 8 

我應該使用哪種類型?我正在以一本書爲例。

回答

2

工作,有的玩,我想我可以說的是,扔它關閉'字符之後。我跑這沒有問題:

CREATE TABLE `products2` (
    `id` int(11) NOT NULL AUTO_INCREMENT, 
    `name` varchar(255) NOT NULL, 
    `sizes` enum('s','m','l','xl') NOT NULL, 
    `colors` enum('red','blue','green','brown','white','black') NOT NULL, 
    `shortdesc` varchar(255) NOT NULL, 
    `longdesc` text NOT NULL, 
    `thumbnail` varchar(255) NOT NULL, 
    `image` varchar(255) NOT NULL, 
    `grouping` varchar(16) NOT NULL, 
    `status` enum('active','inactive') NOT NULL, 
    `category_id` int(11) NOT NULL, 
    `featured` enum('true','false') NOT NULL, 
    `price` float(4,2) NOT NULL, 
    PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1; 
+0

謝謝!這是問題,它現在正在工作:) – m1243 2012-03-15 00:11:37

+0

太棒了!繼續接受詹姆斯的回答(他是第一個發佈的)。 – ScottJShea 2012-03-15 00:13:03

2

使用反引號和撇號,而不是彎引號似乎爲我

CREATE TABLE `products` (
`id` INT NOT NULL AUTO_INCREMENT , 
`name` VARCHAR(255) NOT NULL , 
`shortdesc` VARCHAR(255) NOT NULL , 
`longdesc` TEXT NOT NULL , 
`thumbnail` VARCHAR(255) NOT NULL , 
`image` VARCHAR(255) NOT NULL , 
`sizes` ENUM('s', 'm', 'l', 'xl') NOT NULL , 
`colors` ENUM('red', 'blue', 'green', 'brown', 'white', 'black') NOT NULL , 
`grouping` VARCHAR(16) NOT NULL , 
`status` ENUM('active', 'inactive') NOT NULL , 
`category_id` INT NOT NULL , 
`featured` ENUM ('true', 'false') NOT NULL, 
`price` FLOAT(4, 2) NOT NULL, 
PRIMARY KEY (`id`) 
) ENGINE = MYISAM ;