对于sql来说很新,
我正在尝试创建表,但找不到为什么我使用的语法不起作用
CREATE TABLE customer (
cust-id INT AUTO_INCREMENT NOT NULL,
first-name VARCHAR (20) NOT NULL,
last-name VARCHAR (20) NOT NULL,
address VARCHAR(20) NOT NULL,
phone VARCHAR(20) NOT NULL
PRIMARY KEY(cust-id)
);
我收到的错误消息是
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 '-id INT AUTO_INCREMENT NOT NULL,
first-name VARCHAR(20) NOT NULL,
last-name VA' at line 2
答案 0 :(得分:1)
-不允许以这种形式出现,并且yoz在主键之前缺少逗号
您的创建表可能看起来像
CREATE TABLE customer (
`cust-id` INT AUTO_INCREMENT NOT NULL,
`first-name` VARCHAR (20) NOT NULL,
`last-name` VARCHAR (20) NOT NULL,
address VARCHAR(20) NOT NULL,
phone VARCHAR(20) NOT NULL,
PRIMARY KEY(`cust-id`)
);
或者您将经典__用作列名,例如 cust_id 等
答案 1 :(得分:1)
您可以尝试这样:
CREATE TABLE customer (
cust_id INT AUTO_INCREMENT NOT NULL,
first_name VARCHAR (20) NOT NULL,
last_name VARCHAR (20) NOT NULL,
address VARCHAR(20) NOT NULL,
phone VARCHAR(20) NOT NULL,
PRIMARY KEY(cust_id)
);