Solved

T-SQL Temp Table Results Between Databases

Posted on 2016-11-24
2
22 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:Sonia Bowditch
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 28

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL:  Sigh---Boy, this is fun.... 12 57
T-SQL: Do I need CLUSTERED here? 13 59
MS SQL Server COnditional Where statement 7 85
Perl Versus AWK? 7 52
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

830 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