我编写了一个存储过程,如下所示。它将解析没有错误,但是当我尝试执行它时,它将失败。错误消息显示:消息208,级别16,状态6,过程aspnet_updateUser,第23行 无效的对象名称'dbo.aspnet_updateUser'。
这是存储过程。
USE [PMRS2]
GO
/****** Object: StoredProcedure [dbo].[aspnet_updateUser] Script Date: 05/25/2009 15:29:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[aspnet_updateUser]
-- Add the parameters for the stored procedure here
@UserName nvarchar(50),
@Email nvarchar(50),
@FName nvarchar(50),
@LName nvarchar(50),
@ActiveFlag bit,
@GroupId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
UPDATE dbo.aspnet_Users
SET UserName = @UserName, LoweredUserName = LOWER(@UserName), Email = @Email, FName = @FName, LName = @LName, ActiveFlag = @ActiveFlag, GroupId = @GroupId
WHERE LoweredUserName = LOWER(@UserName)
END
答案 0 :(得分:13)
看起来它可能还不存在,将Alter交换为Create。
答案 1 :(得分:0)
为了避免将来发生这种情况,做我们做的事,永远不要使用alter proc。相反,我们检查是否存在proc并将其删除(如果存在),然后使用新代码创建它:
IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'myProc')
BEGIN
DROP Procedure myProc
END
GO
CREATE PROCEDURE myProc
(add the rest of the proc here)
答案 2 :(得分:0)
这是另一种解决方案
USE [PMRS2]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF OBJECT_ID ( 'dbo.YourProcedureName', 'P' ) IS NOT NULL
DROP PROCEDURE dbo.YourProcedureName;
GO
CREATE PROCEDURE [dbo].[YourProcedureName] (
@UserName varchar(50),
@Password varchar(50))
AS
BEGIN
SET NOCOUNT ON;
select ... (your query)
END