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,213
  • 108
  • 53
  • 73
Srikanth
  • 980
  • 3
  • 16
  • 30

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
  • 242,637
  • 56
  • 362
  • 405
1

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

enter image description here

Noob
  • 710
  • 11
  • 15