Solved

T-SQL Temp Table Results Between Databases

Posted on 2016-11-24
2
18 Views
Last Modified: 2016-11-24
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
Comment
Question by:infosec36
2 Comments
 
LVL 33

Accepted Solution

by:
ste5an earned 250 total points
ID: 41900498
Yup, it is. Exactly like that, assuming that you have sufficient privileges and no foreign constraints exist pointing to table X.
0
 
LVL 24

Assisted Solution

by:Pawan Kumar
Pawan Kumar earned 250 total points
ID: 41900584
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now