2012-03-08 126 views
13
CREATE TABLE users (
user_id  INT(8) NOT NULL AUTO_INCREMENT, 
user_name VARCHAR(30) NOT NULL, 
user_pass VARCHAR(255) NOT NULL, 
user_email VARCHAR(255) NOT NULL, 
user_date DATETIME NOT NULL, 
user_level INT(8) NOT NULL, 
UNIQUE INDEX user_name_unique (user_name), 
PRIMARY KEY (user_id) 
) TYPE=INNODB; 

當SQL服務器上運行該查詢時,我收到以下錯誤:語法錯誤運行MySQL的CREATE TABLE語句

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 'TYPE=INNODB' at line 10 

爲什麼這就要到了任何幫助嗎?

回答

47

而不是

TYPE=INNODB 

設置

Engine=InnoDB 
2

嘗試以下查詢:

CREATE TABLE IF NOT EXISTS `users` (
    `user_id` int(8) NOT NULL AUTO_INCREMENT, 
    `user_name` varchar(30) NOT NULL, 
    `user_pass` varchar(255) NOT NULL, 
    `user_email` varchar(255) NOT NULL, 
    `user_date` datetime NOT NULL, 
    `user_level` int(8) NOT NULL, 
    PRIMARY KEY (`user_id`), 
    UNIQUE KEY `user_name_unique` (`user_name`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 
1

該手冊爲CREATE TABLE不包括TYPE;它似乎使用:

ENGINE = INNODB; 

而這是默認引擎,所以你不需要指定它。