Accesing multiple database using same connection in sql

suppose you want to connect to database DB1 and DB2 in a join statement where connectionstring is same,it can be done
as follows-

connectionstring-Data Source=P06-INF-WS-1\SQLEXPRESS;User ID=sa;Password=sa
select * from DB1.dbo.Table1 tb1 join on DB2.dbo.Table2 tb1 where
Data Source=P06-INF-WS-1\SQLEXPRESS;Database=DB1;User ID=sa;Password=sa
select * from Table1 tb1 join on DB2.dbo.Table2 tb1 where
Table1 is assumed to be in DB1 as its specified in the connection string

1 comment: