Wednesday, 29 March 2017

Use of dot (.) in sql server

The dot (.) is used to separate database name, table name and column name when we use JOINs. The simple example is

select cust.customer_name, sum (detail.total_spend) as total_spend from
customers as cust inner join sales as detail
on cust.customer_id=detail.customer_id
group by cust.customer_name

Ø  When a single dot is used, by default the current user is considered so it becomes username.tablename.
Ø  When two dots are used, by default the current database and user are considered so it becomes dbname.username.tablename.
Ø  When three dots are used, by default the current server, database and user are considered so it becomes servername.dbname.username.tablename


Select * from . Customers 
select * from .. Customers 
select * from  customers 

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts