插入存储过程未编译

时间:2009-10-16 16:04:16

标签: sql-server stored-procedures

在编写创建过程后,Visual Studio 2005仍然要求我创建或更改。可能有什么不对?

USE metroengineeringdatabase

GO
CREATE PROCEDURE dbo.InsertRecords (
@assetcodeId nvarchar(20),
@name_of_asset nvarchar(20),
@unit_no nvarchar(20),
@manufacturer nvarchar(20),
@make nvarchar(20),
@model nvarchar(20),
@capacity nchar(10),
@year_of_manufacture datetime,
@serial_no nvarchar(50),
@attach nvarchar(50),
@siteid nvarchar(50),
@location nvarchar(50),
@omid nvarchar(20),
@smid nchar(20),
@periodic_maintenance_required bit
)   
AS
     INSERT assetdbase
     (
     assetcodeidtxt
     name_of_assettxt,
     unit_notxt,
     manufacturertxt,
     maketxt,
     modeltxt
     capacitytxt,
     year_of_manufacturetxt,
     attachtxt,
     siteidtxt,
     locationtxt,
     smidtxt,
     periodic_maintenance_requiredtxt
    )
     VALUES(
     @assetcodetxt
     @name_of_asset
     @unit_no
     @manufacturer
     @make
     @model
     @capacity
     @year_of_manufacture
     @attach
     @siteid
     @location
     @smid
     @perodic_maintenance_required

     )
    RETURN
GO

2 个答案:

答案 0 :(得分:6)

您在INSERT列表的第一列之后缺少逗号。

您还在VALUES列表中的每个值之间缺少逗号。

答案 1 :(得分:2)

只是为了完成其他人的说法,这里是代码,并且我添加了逻辑以使脚本可以重新运行,所以在第一次运行脚本后你不会得到脚本的创建错误。

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



USE metroengineeringdatabase
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[InsertRecords]') AND type in (N'P', N'PC'))
BEGIN
exec sp_executesql N'CREATE PROCEDURE [dbo].[InsertRecords] AS SELECT ''PROCEDURE Template'''
END
GO


ALTER PROCEDURE dbo.InsertRecords (
@assetcodeId nvarchar(20),
@name_of_asset nvarchar(20),
@unit_no nvarchar(20),
@manufacturer nvarchar(20),
@make nvarchar(20),
@model nvarchar(20),
@capacity nchar(10),
@year_of_manufacture datetime,
@serial_no nvarchar(50),
@attach nvarchar(50),
@siteid nvarchar(50),
@location nvarchar(50),
@omid nvarchar(20),
@smid nchar(20),
@periodic_maintenance_required bit
)   
AS    

INSERT assetdbase
         (
         assetcodeidtxt,
         name_of_assettxt,
         unit_notxt,
         manufacturertxt,
         maketxt,
         modeltxt
         capacitytxt,
         year_of_manufacturetxt,
         attachtxt,
         siteidtxt,
         locationtxt,
         smidtxt,
         periodic_maintenance_requiredtxt
        )
         VALUES(
         @assetcodetxt,
         @name_of_asset,
         @unit_no,
         @manufacturer,
         @make,
         @model,
         @capacity
         @year_of_manufacture,
         @attach,
         @siteid,
         @location,
         @smid,
         @perodic_maintenance_required
         )