Creating temp table identical to an existing one 
Author Message
 Creating temp table identical to an existing one
Any easy way to do this within a SP under SQL Server 7?

For example

CREATE TempTable AS ExistingTable

I want an easy way to append selected records into a temporary table from
an existing table without the need to specify the fields i.e.

INSERT INTO TempTable SELECT * FROM Existing Table WHERE....

Not only this saves programming effort, SPs would be more "stable" in the
long term in the event of one adding fields to an existing table.

Any ideas/workarounds welcome.

Paul.



Sat, 28 Feb 2004 19:26:25 GMT
 Creating temp table identical to an existing one

Paul,

If you only want table and column structure (not constraints or indexes etc), you can
do SELECT INTO
SELECT *
INTO #tmp
FROM tbl
WHERE...

--
Tibor Karaszi, SQL Server MVP
FAQ from Neil & others at: http://www.sqlserverfaq.com


Quote:
> Any easy way to do this within a SP under SQL Server 7?

> For example

> CREATE TempTable AS ExistingTable

> I want an easy way to append selected records into a temporary table from
> an existing table without the need to specify the fields i.e.

> INSERT INTO TempTable SELECT * FROM Existing Table WHERE....

> Not only this saves programming effort, SPs would be more "stable" in the
> long term in the event of one adding fields to an existing table.

> Any ideas/workarounds welcome.

> Paul.



Sat, 28 Feb 2004 19:43:10 GMT
 
 [ 2 post ] 

 Relevant Pages 

1. create a temp table with an existing table stucture

2. create a temp table based on existing table

3. Update table in one db from identical table in another db

4. appending 3 identical tables in to one table

5. Create a Temp Table with Dynamic Column Creation - tough one

6. Update From Identical Temp Table

7. create 2 identical ADODB.Connections -- really just one ?

8. create temp table: -261 Cannot create file for table - Not owner

9. Creating word Macro to copy text and create new files from existing one

10. Script to copy data from one existing column to a new column in another existing table

11. Difference between create table #temp and ##temp ?

12. Create table temp or select into temp.


 
Powered by phpBB® Forum Software