为什么SQL将此标记为'Order'附近的错误/不正确的语法?

时间:2018-05-09 18:35:10

标签: sql-server

有时SQL Server会给我这样的随机错误。我不喜欢SQL,但我很确定这段代码没有错...

  

'Order'附近的语法不正确

CREATE TABLE Order
(
    OrderNumber INTEGER PRIMARY KEY,
    OrderDate DATE,
    CustomerNumber INTEGER,
    CustomerPONumber INTEGER,
    OrderTotal FLOAT,
    OrderStatus VARCHAR(10),
    OrderSpecialCharges FLOAT,
    OrderSpecialChargeDescription VARCHAR(50),
    ShipName VARCHAR (20),
    ShipAddress1 VARCHAR (10),
    ShipAddress2 VARCHAR (10),
    ShipCity VARCHAR (10),
    ShipState CHAR (2),
    ShipZip INTEGER,
    FOREIGN KEY (CustomerNumber) REFERENCES Customer
);

1 个答案:

答案 0 :(得分:6)

您需要使用set root=C:\Users\john.doe\AppData\Local\Continuum\anaconda3 call %root%\Scripts\activate.bat %root% call conda list pandas pause

[]

您应该避免使用reserved keywords作为标识符。我建议重命名为CREATE TABLE [Order] ( OrderNumber INTEGER PRIMARY KEY, OrderDate DATE, CustomerNumber INTEGER, CustomerPONumber INTEGER, OrderTotal FLOAT, OrderStatus VARCHAR(10), OrderSpecialCharges FLOAT, OrderSpecialChargeDescription VARCHAR(50), ShipName VARCHAR (20), ShipAddress1 VARCHAR (10), ShipAddress2 VARCHAR (10), ShipCity VARCHAR (10), ShipState CHAR (2), ShipZip INTEGER, FOREIGN KEY (CustomerNumber) REFERENCES Customer );

修改

正如评论中提到的其他人一样,您应该避免使用近似数字数据类型(Orders)并使用准确的数据类型(FLOAT/REAL/DOUBLE)。这将节省您将来的时间。例如:

Avg of float inconsistency