[英]How to resolve invalid object name in Stored procedure script?
I've created a stored procedure to query all the records from a table named EscalationStatus
.我创建了一个存储过程来查询名为
EscalationStatus
的表中的所有记录。
But on execute of the sql script in Sql Server 2014 Management Studio , an error is thrown where I declare the procedure name -但是在 Sql Server 2014 Management Studio 中执行 sql 脚本时,会在我声明过程名称的地方引发错误 -
"Msg 208, Level 16, State 6, Procedure GET_STATUS, Line 19
Invalid object name 'dbo.GET_STATUS'."
I checked the following that the procedure name matched the name of the sql script, and that the DB name is valid which they are.我检查了以下过程名称是否与 sql 脚本的名称匹配,并且数据库名称是有效的。
I also took the step of "Refreshing Intellisense cache" which didn't clear out the error.我还采取了“刷新智能感知缓存”的步骤,但没有清除错误。
Question: Does anyone know why the Procedure name is evaluated as an invalid object name ?问题:有谁知道为什么过程名称被评估为无效的对象名称?
The table name is EscalationStatus
:表名是
EscalationStatus
:
`GET_STATUS` stored procedure:
USE [NOTIFICATION]
GO
/****** Object: StoredProcedure [dbo].[GET_STATUS] Script Date: 12/05/2016 11:50:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[GET_STATUS]
AS
BEGIN
SELECT
[EscStatus]
,[Color]
FROM NOTIFICATION.dbo.EscalationStatus
END
remove the following line from the Alter procedure script or comment it out at the very first line in the above query.:从 Alter 过程脚本中删除以下行或在上述查询的第一行将其注释掉。:
`GET_STATUS` stored procedure:
Use this:用这个:
--`GET_STATUS` stored procedure:
USE [NOTIFICATION]
GO
/****** Object: StoredProcedure [dbo].[GET_STATUS] Script Date: 12/05/2016 11:50:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[GET_STATUS]
AS
BEGIN
SELECT
[EscStatus]
,[Color]
FROM NOTIFICATION.dbo.EscalationStatus
END
Follow this template to CREATE/ALTER procedure按照此模板创建/更改程序
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[P1]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[P1]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[P1]
AS
BEGIN
SELECT 1 AS VAL
END
GO
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.