首页 > 解决方案 > 创建全新表时出错

问题描述

我试图用代码创建一个全新的表:

MySQL [distributor]> create table order
    -> (
    -> order_num integer  not null,
    -> order_date datetime not null,
    -> cust_id chat(10) not null
    -> );

它会产生错误:

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 'order
(
order_num integer  not null,
order_date datetime not null,
cust_id chat(' at line 1

由于 SQL 不区分大小写,我已多次检查以确保我的代码没有问题。

我的代码有什么错误?

标签: mysqlsql

解决方案


您的查询有两个问题:首先,order是 MySQL 保留字。其次,你有chatwhich should be char。试试这个(将表重命名为orders):

CREATE TABLE orders
(
order_num integer  not null,
order_date datetime not null,
cust_id char(10)
);

推荐阅读