为什么我会出错?
--Q1
CREATE table Aorders (
Id INT IDENTITY NOT NULL,
CreatedDate Date NOT NULL,
BillingCountry varchar Not Null,
MerchId int Not null,
OrderStatus varchar Not null,
);
--Q2
select * from Aorders
--Q3 edited as suggested here but still get an error 在Aorders (CreatedDate、BillingCountry、MerchId、OrderStatus)中插入值(“2001-01-01”、“以色列”、“5”、“批准”);
发布于 2019-08-03 16:14:51
您必须定义varchar列的长度,如:
CREATE table Aorders (
Id INT IDENTITY NOT NULL,
CreatedDate Date NOT NULL,
BillingCountry varchar(100) Not Null,
MerchId int Not null,
OrderStatus varchar(100) Not null,
); 来自char和varchar (Transact-SQL):
当在数据定义或变量声明语句中未指定n时,默认长度为1。
发布于 2019-08-03 15:56:29
在执行insert时,最佳实践是显式列出所有列,并对日期使用标准格式:
INSERT INTO Aorders (CreatedDate, BillingCountry, MerchId, OrderStatus)
VALUES ('2001-01-01', 'Israel', 5 ,'Approved');您的具体错误是因为您在VALUES()列表中有四个值,但是表中有五个列。
发布于 2019-08-03 15:59:23
您没有正确地执行查询。我认为您希望ID自动递增,但您还没有声明。作出以下修改:
CREATE table Aorders ( Id INT IDENTITY NOT NULL
,CreatedDate Date NOT NULL
,BillingCountry varchar Not Null
,MerchId int Not null
,OrderStatus varchar Not null);现在输入您插入的查询。并确保文档中适当的日期格式。
https://stackoverflow.com/questions/57339876
复制相似问题