Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用T-SQL将啤酒插入啤酒表时出错_Asp.net_Sql_Tsql_Database Design_Sql Insert - Fatal编程技术网

Asp.net 使用T-SQL将啤酒插入啤酒表时出错

Asp.net 使用T-SQL将啤酒插入啤酒表时出错,asp.net,sql,tsql,database-design,sql-insert,Asp.net,Sql,Tsql,Database Design,Sql Insert,我正在尝试将7种不同类型的啤酒插入到我使用T-SQL创建的名为Beers的表中。我的值中不断出现错误,但消息如下: 执行查询时发生以下错误: Server: Msg 156, Level 15, State 1, Line 6 Incorrect syntax near the keyword 'VALUES'. Incorrect syntax near the keyword 'VALUES'. Incorrect syntax near the keyword 'VALUES'. I

我正在尝试将7种不同类型的啤酒插入到我使用T-SQL创建的名为Beers的表中。我的值中不断出现错误,但消息如下:

执行查询时发生以下错误:

Server: Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'VALUES'. 
Incorrect syntax near the keyword 'VALUES'. 
Incorrect syntax near the keyword 'VALUES'. 
Incorrect syntax near the keyword 'VALUES'. 
Incorrect syntax near the keyword 'VALUES'. 
Incorrect syntax near the keyword 'VALUES'. 
Incorrect syntax near the keyword 'VALUES'.
我有什么遗漏吗?我想不出是什么错误

这是我的SQL

--将啤酒添加到数据库

SET IDENTITY_INSERT [dbo].[Beers] ON

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 1)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType],    [BeerRating], [Enabled], [DateInserted],[DateLastActivity],
 VALUES (1, 'Black_Butte', '$9.00', 'porter', NULL, 1, '20071111', '20071111')

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 2)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType],  [BeerRating],  [Enabled], [DateInserted],[DateLastActivity],
 VALUES (2, 'Corona', '$5.00', 'lager', NULL, 1, '20071111', '20071111')

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 3)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity],
 VALUES (3, 'Duvel', '$12.00', 'pale ale', NULL, 1, '20071111', '20071111')

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 4)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity],
 VALUES (4, 'Guinness', '$7.00', 'stout', NULL, 1, '20071111', '20071111')

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 5)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity],
 VALUES (5, 'Heineken', '$6.00', 'lager', NULL, 1, '20071111', '20071111')

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 6)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity],
 VALUES (6, 'Pilsner_Urquell', '$6.50', 'pilsner', NULL, 1, '20071111', '20071111')

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 7)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity],
 VALUES (7, 'Stone', '$10.00', 'IPA', NULL, 1, '20071111', '20071111')


SET IDENTITY_INSERT [dbo].[Beers] OFF

值之前缺少右括号:

INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity]) VALUES 

您缺少右括号,并在每个
INSERT
语句的末尾添加了额外的逗号

如下图所示,它将起作用

来自

,[DateLastActivity],
 VALUES (1, 'Black_Butte', '$9.00', 'porter', NULL, 1, '20071111', '20071111')

,[DateLastActivity])
 VALUES (1, 'Black_Butte', '$9.00', 'porter', NULL, 1, '20071111', '20071111')
试试这个:

如果不存在(从[dbo].[Beers]中选择[BeerId],其中[BeerId]=1) 插入到([dbo]。[Beers]([BeerId]、[BeerName]、[BeerPricePerBaggle]、[BeerType]、[BeerRating]、[Enabled]、[DateInserted]、[DateLastActivity])
值(1,'Black_Butte'、'$9.00'、'porter',NULL,1,'20071111'、'20071111')

您是绝对正确的。谢谢您!在长时间的工作之后,让第二双眼睛看东西会有帮助。我会记下答案。再次感谢!