简体   繁体   中英

MS SQL Selecting tables

I have database A , A_Archive . I have T table in A and also A_Archive (same structure) Can I do a select (or even create a view ) to see somthing like this:

.
.
.
A_Archive records
.
.
.
A records

and how?

Thanks

You should be able to achieve this using fully qualified names, like:

SELECT * FROM A_Archive.dbo.T
UNION ALL
SELECT * FROM A.dbo.T

depending on whether dbo is the correct scheme. Also you need to make sure the user excuting the select does have the necessary rights on both databases.

If the both databases are on the same server you can simply write this query

SELECT * FROM [DatabaseName].dbo.[tableName]
  UNION ALL
SELECT * FROM [AnotherDatabaseName].dbo.[AnothertableName]

But if these two databases are on different servers you need to consider sp_addlinkedserver to create a server link. read more from this link

Hope it will help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM