Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Scema Issue Expand / Collapse
Author
Message
Posted Wednesday, October 17, 2012 10:08 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, October 18, 2012 5:07 AM
Points: 2, Visits: 6
I have a user on which i have acess over 2 databases say AdventreWork and AdventureWorkDW. Now i have to write a query in which i dont have to mention a db name but still it will give me the result.

example :
AdventureWork : Employee (Table Name)
AdventureWorkDW : Department (Table Name)

QUERY

Select Empid, Deptname From Employee E INNER JOIN Department D ON (E.Dept_id=D.Dept_id) Will this work??-----
Insted if i write
Select Empid, Deptname From AdventureWork .Employee E INNER JOIN AdventureWorkDW .Department D ON (E.Dept_id=D.Dept_id)--- This is working fine.
But our requiremnt is we dont want to mention the schema name. Is tis possible??
Post #1373926
Posted Wednesday, October 17, 2012 10:55 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Monday, July 7, 2014 1:06 PM
Points: 1,478, Visits: 1,025
Your sample query
QUERY

Select Empid, Deptname From Employee E INNER JOIN Department D ON (E.Dept_id=D.Dept_id) Will this work??-----
Insted if i write
Select Empid, Deptname From AdventureWork .Employee E INNER JOIN AdventureWorkDW .Department D ON (E.Dept_id=D.Dept_id)--- This is working fine.
But our requiremnt is we dont want to mention the schema name. Is tis possible??


This is not describing a schema, AdventureWorkDW, and AdventureWork are database names.

If you want to eliminate the database name from your query then you must be connected to that database.
For Example
Use [AdventureWorks]
SELECT *
FROM [Production].[Product]

Works.

If your purposly connected to AdventureWorks, and you need data from the AdventureWorkDW database then you need to fully qualify the AdventureWorksDW table in your query by using the [DatabaseName].[Schema].[Table Name] in your Join.

Like I mentioned I'm confused by what your asking because you seem to be calling database names Schemas, and they are different. and the examples you posted do not work as you mention.
Post #1373951
Posted Wednesday, October 17, 2012 10:56 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 12:03 PM
Points: 1,277, Visits: 2,208
In the database you are working in, you can create a synonym for each table you want to access outside of the account's database you are working in.

I don't know if this will meet your criteria, as you would specify the database, schema, and table name in the synonym, but the query could then be written using the synonyms with the accounts default database and schema.
Post #1373953
Posted Thursday, October 18, 2012 5:23 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, October 18, 2012 5:07 AM
Points: 2, Visits: 6
Thanks for the reply. I was a bit confused about this. I will give you my exact query.

I have created a connection through my application on SQL SERVER (sql server authentication) which is for AdventureWorks Database. This is for user1. User1 have access on AdventureWorksDW database also. The query which i have written is

SELECT t1.Name , t2.ModelName FROM AdventureWorks .Production.Product t1 LEFT JOIN AdventureWorksDW.dbo.DimProduct t2 ON (t1.ProductID=t2.ProductKey)

This query is work fine, this is working fine even in this case also.

SELECT t1.Name , t2.ModelName FROM Production.Product t1 LEFT JOIN AdventureWorksDW.dbo.DimProduct t2 ON (t1.ProductID=t2.ProductKey)

Now my question is will this query work if i write a query like
SELECT t1.Name , t2.ModelName FROM Production.Product t1 LEFT JOIN dbo.DimProduct t2 ON (t1.ProductID=t2.ProductKey)

Help me out with this.
Post #1374278
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse