SQL有什么问题?

时间:2010-11-25 02:05:49

标签: 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)

错误是

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

1 个答案:

答案 0 :(得分: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成为可索引的数据类型,因此也就是主键列......