0

I have View V_empmaster in MYemp database in Sqlserver2008 server, Now I want to use V_empmaster view in MASTERDB database in Same server. My query is : select * from dbo.MasterDB.V_empmaster;

but SQL Execution Error message is displayed Error source: .NetSqlclientDataProvider Error Message: Invalid objectname 'dbo.V_empmaster'

Anyone help me out what is my mistake even if it is silly

2 Answers 2

3

The parts of a name are server.database.schema.object. You've got schema and database the wrong way around:

select * from MasterDB.dbo.V_empmaster
Sign up to request clarification or add additional context in comments.

Comments

1

When you refer view from another database in the same server, you should use three part object qualifier:

-- set context to MYemp db
use MYemp
GO
-- access V_empmaster data in MYemp db
select * from dbo.V_empmaster
GO
-- switch context to MASTERDB
use MASTERDB
GO
-- to access V_empmaster from MYemp, three part qualifier
-- ([dbName].[schemaName].[objectName]) is used
select * from MYemp.dbo.V_empmaster 

1 Comment

Thanks for the Solution! It is working when I executed it as QUERY. I tried to copy in View of MASTERDB but getting error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.