2012-02-27 177 views
-2
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; 

CREATE TABLE 'orders' ( 
    'id' INT UNSIGNED NOT NULL AUTO_INCREMENT, 
    'user_id' INT UNSIGNED NOT NULL, 
    'transaction_id' VARCHAR(19) NOT NULL, 
    'payment_status' VARCHAR(15) NOT NULL, 
    'payment_amount' DECIMAL(6,2) UNSIGNED NOT NULL, 
    'payment_date_time' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    PRIMARY KEY ('id'), 
    KEY 'user_id' ('user_id') 
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

CREATE TABLE 'pages' ( 
    'id' MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, 
    'category_id' SMALLINT UNSIGNED NOT NULL, 
    'title' VARCHAR(100) NOT NULL, 
    'description' TINYTEXT NOT NULL, 
    'content' LONGTEXT NOT NULL, 
    'date_created' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    PRIMARY KEY ('id'), 
    KEY 'category_id' ('category_id'), 
    KEY 'creation_date' ('date_created') 
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

CREATE TABLE 'pdfs' ( 
    'id' SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, 
    'tmp_name' CHAR(40) NOT NULL, 
    'title' VARCHAR(100) NOT NULL, 
    'description' TINYTEXT NOT NULL, 
    'file_name' VARCHAR(40) NOT NULL, 
    'size' MEDIUMINT UNSIGNED NOT NULL, 
    'date_created' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    PRIMARY KEY ('id'), 
    UNIQUE KEY 'tmp_name' ('tmp_name'), 
    KEY 'date_created' ('date_created') 
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

CREATE TABLE 'users' ( 
    'id' INT UNSIGNED NOT NULL AUTO_INCREMENT, 
    'type' ENUM ('member','admin') NOT NULL, 
    'username' VARCHAR(30) NOT NULL, 
    'email' VARCHAR(80) NOT NULL, 
    'pass' VARBINARY(32) NOT NULL, 
    'first_name' VARCHAR(20) NOT NULL, 
    'last_name' VARCHAR (40) NOT NULL, 
    'date_expires' DATE NOT NULL, 
    'date_created' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    'date_modified' TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', 
    PRIMARY KEY ('id'), 
    UNIQUE KEY 'username' ('username'), 
    UNIQUE KEY 'email' ('email') 
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

.................................. ...........................................SQL語法錯誤 - 找不到錯誤

我找不到這裏的SQL錯誤。

MySQL表示:

#1064 - 你在你的SQL語法錯誤; ('id'SMALLINT NOT NULL AUTO_INCREMENT,'category'VARCHAR(30)NOT'on line 1

請幫忙查看對應於您的MySQL服務器版本的手冊。我使用的是共享服務器上的MySQL 4.4.x到。

+0

不確定這是否是問題,但您不需要圍繞表名引用單引號。可能是什麼東西扔掉了。我會先創建一張表,看看它是否是下行的,可能會崩潰它 – Brian 2012-02-27 15:48:06

+3

MySQL 4.4?真? – gbn 2012-02-27 15:51:00

回答

7

你跟'周圍的表和列名,它應該是`(反引號)

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

我剛剛輸入了這個; p – RichardW11 2012-02-27 15:49:47

0

擺脫你的單引號或正如@Joachim Isaksson所說的那樣,使用反引號`

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

此外,下一次,簡化您的問題。第一個CREATE TABLE聲明有問題。沒有必要打印一切。另外一些格式也會很好:-)。

+0

感謝您的幫助。問題現在已經解決了。我剛開始學習MySQL/PHP,現在我發現它是一場艱苦的戰鬥。 cc:@Joachim Isaksson – 2012-02-27 16:25:57