收到此SQL代码的语法错误

时间:2016-11-21 17:45:31

标签: mysql sql

语法错误: -

CREATE TABLE CUSTOMER (
CustomerID        Int    NOT NULL IDENTITY(1,1) PRIMARY KEY, 
CustomerName      Char(25)                      NOT NULL,
CustomerDeliveryAddress  Char(25)               NOT NULL,                                       
CustomerPhone            Char (10)              NOT NULL,
CustomerBillingAddress   Char(25)               NOT NULL,
CustomerCreditCard       Int                    NOT NULL,
CONSTRAINT  CustomerPK          PRIMARY KEY(CustomerID)
);

2 个答案:

答案 0 :(得分:2)

在mysql中没有任何名为identity的内容,而是有AUTO_INCREMENT

CREATE TABLE CUSTOMER (
CustomerID        INT NOT NULL AUTO_INCREMENT  PRIMARY KEY, 
CustomerName      Char(25)                      NOT NULL,
CustomerDeliveryAddress  Char(25)               NOT NULL,                                       
CustomerPhone            Char (10)              NOT NULL,
CustomerBillingAddress   Char(25)               NOT NULL,
CustomerCreditCard       Int                    NOT NULL

);

答案 1 :(得分:1)

你必须只声明一次主键

CREATE TABLE CUSTOMER (
CustomerID        INT NOT NULL AUTO_INCREMENT,
CustomerName      Char(25)                      NOT NULL,
CustomerDeliveryAddress  Char(25)               NOT NULL,
CustomerPhone            Char (10)              NOT NULL,
CustomerBillingAddress   Char(25)               NOT NULL,
CustomerCreditCard       Int                    NOT NULL,
PRIMARY KEY(CustomerID));