2013-01-10 119 views
0

您好我想創建在MySQL使用SQL表,但我不斷收到error.Here是我的代碼:創建表時會引發錯誤

USE e-commerce 
    CREATE TABLE `categories` (
`id` SMALLINT NOT NULL AUTO_INCREMENT, 
`category` VARCHAR(30) NOT NULL, 
PRIMARY KEY (`id`), 
UNIQUE KEY `category` (`category`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

當我試圖在phpMyAdmin SQL控制檯運行此得到這個錯誤:

#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 'CREATE TABLE `categories` (`id` SMALLINT NOT NULL AUTO_INCREMENT, `category` ' at line 2 

我在做什麼錯?

回答

10

添加分號後use

USE e-commerce; 
CREATE TABLE `categories` (
    `id` SMALLINT NOT NULL AUTO_INCREMENT, 
    `category` VARCHAR(30) NOT NULL, 
    PRIMARY KEY (`id`), 
    UNIQUE KEY `category` (`category`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 
+0

@MahmoudGamal:感謝花花公子。 –

2

缺少分號

USE e-commerce; 
    CREATE TABLE `categories` (
`id` SMALLINT NOT NULL AUTO_INCREMENT, 
`category` VARCHAR(30) NOT NULL, 
PRIMARY KEY (`id`), 
UNIQUE KEY `category` (`category`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 
2

在你的代碼有2個查詢。你應該總是用分號結束查詢。

所以請嘗試以下

USE e-commerce; 
CREATE TABLE `categories` (
`id` SMALLINT NOT NULL AUTO_INCREMENT, 
`category` VARCHAR(30) NOT NULL, 
PRIMARY KEY (`id`), 
UNIQUE KEY `category` (`category`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8;