本文介绍了在Microsoft SQL Server Management Studio中获得此错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的查询标签如下:
insert into dbo.booking
values ('Member ID', 'Court ID', 'Date', 'Timeslot', 'Price')
insert into dbo.booking
values ('1', '1', '19/12/19', '07:00 - 17:00', 'Morning £12 + 2')
select * from dbo.booking
但是,执行该错误时会出现此错误:
But, I get this error when I execute it:
推荐答案
INSERT错误使用了。
The INSERT is wrongly used.
像这样尝试:
insert into dbo.booking ([Member ID], [Court ID], [Date], [Timeslot], Price) values
(1, 1, '2019-12-19', '07:00 - 17:00', N'Morning £12 + 2')
您可以从参考文献,其语法更类似于此示例:
You can see from the reference here that the syntax is more like this example:
INSERT INTO database_name.schema_name.table_or_view_name
( column1, column2 ) VALUES
( 'text', 42 ),
( 'other text', 69 )
整数值不需要单引号
NVARCHAR的值应该以N为前缀。
integer values don't need the single-quotes.
And values for a NVARCHAR should be prefixed with a N.
您遇到的错误是因为第一次插入尝试插入文本值
并且仅在该文本可以隐式转换为数字的情况下有效。
The error that you had was because the first insert tried to insert text values into number fields.
And that only works if that text can be implicitly casted to a number.
这篇关于在Microsoft SQL Server Management Studio中获得此错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!