Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 31
  • Last Modified:

T-SQL Temp Table Results Between Databases

Hello Experts,

This may be a silly question but I would like help with the following scenario.

Database 1
SELECT *
INTO #tmptable1
FROM table 1

[b][/Database 2b]
TRUNCATE TABLE X
INSERT INTO TABLE X
SELECT * FROM #tmptable1 in Database1
INTO TABLE X in Database2

Is this even possible?

Thanks
Infosec36
0
Sonia Bowditch
Asked:
Sonia Bowditch
2 Solutions
 
ste5anSenior DeveloperCommented:
Yup, it is. Exactly like that, assuming that you have sufficient privileges and no foreign constraints exist pointing to table X.
0
 
Pawan KumarDatabase ExpertCommented:
Yes it is possible in Single Session with proper access.

Also use 4 part name everytime.

Try something like..

--

SELECT * INTO #tmptable1
FROM servername.database1.schema.table1

TRUNCATE TABLE servername.Database2.schema.X

INSERT INTO TABLE servername.Database2.schema.X
SELECT * FROM #tmptable1

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now