Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Scema Issue


Scema Issue

Author
Message
kunal_ghosh84
kunal_ghosh84
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
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??
Ray M
Ray M
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1491 Visits: 1076
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.
sestell1
sestell1
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2209 Visits: 3418
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.
kunal_ghosh84
kunal_ghosh84
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search