我正在尝试将7种不同类型的啤酒插入我使用T-SQL创建的名为Beers的表中。我的VALUES中不断出现错误,但有消息:
执行查询时出现以下错误:
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
答案 0 :(得分:0)
您在VALUES之前缺少右括号:
INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity]) VALUES
答案 1 :(得分:0)
您缺少关闭括号并在每个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')
答案 2 :(得分:0)
试试这个:
如果不是EXISTS(从[dbo]中选择[BeerId]。[Beers] WHERE [BeerId] = 1) INSERT INTO([dbo]。[Beers]([BeerId],[BeerName],[BeerPricePerBottle],[BeerType],[BeerRating],[Enabled],[DateInserted],[DateLastActivity]) VALUES(1,'Black_Butte','$ 9.00','搬运工',NULL,1,'20071111','20071111')