Create Temp Tables in Sql Server and Oracle

From Relyimah

Jump to: navigation, search

Occasionally, you need to drop a table and re-create it for whatever reason when upgrading a database. But, what do you do with the data in this table while you are doing this? Simple! Create a temporary table to hold the data.

In the past, I have generated a 'CREATE TABLE' script to mimic the current table structure, inserted the data into this new table, and then done the modifications. This is a bit cumbersome, and looks messy. Wouldn't it be nice if you could have a simple 1 - 2 liner that would do this for you? You Can!

Sql Server:

SELECT * 
INTO schema.tablename_temp 
FROM schema.tablename

Oracle:

CREATE TABLE owener.tablename_temp 
AS SELECT * FROM owner.tablename
Personal tools