Skip to main content
 首页 » 编程设计

c#之为什么 SQL 查询不运行

2024年02月13日13exmyth

我正在使用 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

为什么会出现此错误?

请您参考如下方法:

取出GO语句。

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

SQL Server GO Keyword