无效的对象名称 - 存储过程 [英] Invalid Object Name - Stored Procedure
问题描述
我正在通过 SSMS 在 SQL Server 中创建一个存储过程.
I am creating a stored procedure in SQL Server via SSMS.
我已经编写了下面的存储过程,但是当我点击执行时,它给出了错误:
I have written the stored procedure below, however when I click execute it am given the error:
Msg 208, Level 16, State 6, Procedure NewQuestion, Line 11无效的对象名称hgomez.NewQuestion".
表的所有权是正确的.(hgomez.Questions)
the table is ownership is correct. (hgomez.Questions)
USE [devworks_oscar]
GO
/****** Object: StoredProcedure [hgomez].[NewQuestion] Script Date: 10/23/2011 23:55:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [hgomez].[NewQuestion]
(
@QUESTIONNAME nvarchar(50),
@QUESTION_ID int OUTPUT
)
AS
/* SET NOCOUNT ON */
INSERT INTO [Questions] (QuestionText) VALUES (@QUESTIONNAME)
SET @QUESTION_ID = SCOPE_IDENTITY();
RETURN
提前致谢
推荐答案
我很喜欢总是在我的 CREATE
语句之前添加明确的检查是否存在并在找到时删除.
I was a fan of always prepending my CREATE
statements with an explicit check for existence and dropping if it was found.
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME = 'NewQuestion' AND ROUTINE_SCHEMA = 'hgomez')
BEGIN
DROP PROCEDURE hgomez.NewQuestion
END
GO
-- this is always a CREATE
CREATE PROCEDURE [hgomez].[NewQuestion]
(
@QUESTIONNAME nvarchar(50),
@QUESTION_ID int OUTPUT
)
AS
/* SET NOCOUNT ON */
INSERT INTO [Questions] (QuestionText) VALUES (@QUESTIONNAME)
SET @QUESTION_ID = SCOPE_IDENTITY();
RETURN
这在权限方面可能有点麻烦,因此其他人使用一种方法,即他们创建存根方法只是为了立即ALTER
它.
That can be a bit of hassle with regard to permissions so others use an approach wherein they create a stub method only to immediately ALTER
it.
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME = 'NewQuestion' AND ROUTINE_SCHEMA = 'hgomez')
BEGIN
EXEC ('CREATE PROCEDURE hgomez.NewQuestion AS SELECT ''stub version, to be replaced''')
END
GO
-- This is always ALTER
ALTER PROCEDURE [hgomez].[NewQuestion]
(
@QUESTIONNAME nvarchar(50),
@QUESTION_ID int OUTPUT
)
AS
/* SET NOCOUNT ON */
INSERT INTO [Questions] (QuestionText) VALUES (@QUESTIONNAME)
SET @QUESTION_ID = SCOPE_IDENTITY();
RETURN
这篇关于无效的对象名称 - 存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!