2010-11-25 69 views
0

CREATE TABLE IF NOT EXISTS customers (customer_id TEXT NOT NULL, time_stamp TIMESTAMP NOT NULL, customer_info TEXT), PRIMARY KEY (time_stamp)SQL有什麼問題?

的錯誤是

mysql> CREATE TABLE IF NOT EXISTS customers (customer_id TEXT NOT NULL, time_stamp TIMESTAMP NOT NULL, 
     customer_info TEXT), PRIMARY KEY (time_stamp); 
ERROR 1064 (42000): 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 ' PRIMARY KEY (time_stamp)' at line 1 
+2

你得到什麼錯誤? – BoltClock 2010-11-25 02:06:35

+1

是`PRIMARY KEY`之前的那個逗號嗎?順便說一下,時間戳對於客戶來說似乎不是一個好PK。它不應該是'customer_id`嗎? – Kos 2010-11-25 02:08:18

回答

4

的主鍵列需要在CREATE TABLE括號內定義:

CREATE TABLE IF NOT EXISTS customers (
    customer_id TEXT NOT NULL, 
    time_stamp TIMESTAMP NOT NULL, 
    customer_info TEXT, 
    PRIMARY KEY (time_stamp) 
) 

我很好奇,爲什麼你沒有做customer_id可轉位數據類型,因此主鍵列...