【问题标题】:Why won't the SQL Query run?为什么 SQL 查询不运行?
【发布时间】:2014-05-31 14:25:28
【问题描述】:

我使用的是 SQL Server 2005。

这是我遵循的步骤:

  1. 右键单击数据连接。
  2. 添加了到服务器的连接。
  3. 已选择 Microsoft SQL Server(SQL 客户端)。
  4. 创建了数据库。
  5. 右键单击表格部分。
  6. 按添加新查询。
  7. 插入了 SQL 语句。
  8. 按下执行 SQL 语句。

我使用这个 SQL 语句来尝试运行它:

CREATE TABLE [dbo].[Title](
    [id] [int] IDENTITY(1000,1) NOT NULL,
    [name] [nvarchar](30) NULL,
    [artist] [nvarchar](40) NULL,
    [price] [money] NULL,
    [length] [float] NULL,
    CONSTRAINT [PK_title] PRIMARY KEY CLUSTERED  ( [id] ASC )
) ON [PRIMARY]
GO

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Dhoom Machale', N'Aditi Singh Sharma', CAST(5.99 AS Money), 7.45)

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Mat Maari', N'Kunal Ganjawala, Sunidhi Chauhan', CAST(4.50 AS Money), 6.45)

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Paani Paani',N'Honey Singh', CAST(2.90 AS Money), 4.5)

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Dhanush Sachin Anthem', N'Dhanush', CAST(3.50 AS Money), 4.45)

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Hamari Atariya Pe', N'Rekha Bhardwaj', CAST(4.00 AS Money), 4.43)

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Kabhi Jo Badal Barse', N'Arijit Singh', CAST(3.40 AS Money), 5.05)

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Do Rang Duniya Ke Aur Do Raste', N'Mukesh', CAST(2.75 AS Money), 4.35)

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Mera Joota Hai Japani', N'Mukesh', CAST(1.97 AS Money), 5.15)

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Full Jhol', N'Mika Singh, Akasa Singh', CAST(2.45 AS Money), 5.05)

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Kaddu Katega', N'Antara Mitra', CAST(3.24 AS Money), 4.25)

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Tujse Door Jo Hota Hunn',N'Gajendra Verma', CAST(2.45 AS Money), 3.45)

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Chura Liya Hai Tumne Jo Dil Ko',N'Asha Bhosle, Mohammad Rafi', CAST(3.55 AS Money), 4.05)

INSERT INTO [dbo].[Title] ([name],[artist], [price], [length]) 
VALUES (N'Deewana Mujh Sa Nahin',N'Mohammad Rafi', CAST(4.35 AS Money), 4.25)

我得到的错误是this

为什么会出现这个错误?

【问题讨论】:

  • 你确定你是在“添加新查询”而不是“添加新表”中做的吗?也许你只能在那里创建表格。
  • SQL 没有问题,看看这个小提琴:sqlfiddle.com/#!3/90760/1。这在 2008 年运行,应该没有什么区别。所以我建议你在哪里以及如何运行它有其他问题。
  • @GrantWinney Nah 我用我学到的其他语句尝试了它,结果很好。
  • @MihaiBejenariu 非常感谢它现在工作了!
  • @rudym 我按下了查询。

标签: c# sql sql-server sql-server-2005 visual-studio-2012


【解决方案1】:

取出GO 声明。

Visual Studio / SQL Server Data Tools 使用 ADO.NET 数据提供程序。 GO 无法被数据库引擎识别,只能被 Management Studio 和 OSQL/SQLCMD 识别。

SQL Server GO Keyword

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 1970-01-01
    • 2011-07-06
    • 1970-01-01
    • 2010-11-05
    • 2015-05-22
    • 1970-01-01
    相关资源
    最近更新 更多