| |

VerySource

 Forgot password?
 Register
Search
View: 730|Reply: 5

Two tables are distributed in two different databases, how to do a natural join for them.

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-15 18:00:01
| Show all posts |Read mode
Two tables are distributed in two different databases, how to do a natural join for them. These two databases are placed on the same database server.
Reply

Use magic Report

0

Threads

23

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-1-19 09:27:01
| Show all posts
format:

Database name.dbo.table name

or

Database name: table name

Such as:

select A. *, B. *
from database 1: Table 1 A
        inner join database 2 .. Table 2 B on A.ID = B.ID
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-1-19 14:36:02
| Show all posts
If table a is in db1 and table b is in db2

use db2;
select * from db1.dbo.a, b where db1.dbo.a.primary key = b.primary key;
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-1-19 22:00:02
| Show all posts
ALTER PROCEDURE dbo.SelectAnnounce
AS
/ * SET NOCOUNT ON * /
SELECT A. *
FROM Customer.dbo.Announce A
INNER JOIN aspnetdb.dbo.aspnet_Users U
ON A.AuthorID = U.UserID
/ * select * from Announce * /

Hint: The object name Customer.dbo.Announce A is invalid.
what happened?
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-1-21 14:18:01
| Show all posts
SELECT *
FROM dbo.Announce
You can query the data.
but
SELECT *
FROM Customer.dbo.Announce
It won't work.
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-23 23:54:01
| Show all posts
SELECT A. *
FROM Customer..Announce A
INNER JOIN aspnetdb..aspnet_Users U
ON A.AuthorID = U.UserID

Try this?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list