2

I have created a EmpDB and created a table "EmpTable" when I try to create a simple SP I am getting compile time error "Invalid Object name dbo.EmpTable" - why?

Following is the sql statements

use EmpDB;
Go
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================

CREATE PROCEDURE usp_GetEmpNames

AS

SELECT * FROM dbo.EmpTable
gnat
  • 6,205
  • 103
  • 52
  • 72
Srikanth
  • 983
  • 3
  • 16
  • 28

2 Answers2

1

I just created a test version and ran your script with any issues.

A few things to check:

If you run just the SELECT does it run?

SELECT * FROM dbo.EmpTable

If not, then verify the schema the EmpTable is in and replace the dbo.

SELECT * FROM yourSchemaNameGoesHere.EmpTable 

Make sure that your table that you created is in the correct database EmpDB and you didn't accidentally create your table in the wrong database.

Taryn
  • 234,956
  • 54
  • 359
  • 399
1

Make sure you have selected the right database on which you run the query. That was my issue.

enter image description here

Noob
  • 580
  • 7
  • 15