Innova
Innova

Reputation: 4971

dynamically create table statement in sql

how to dynamically create a table with same columns as that of previous table. in sql

Upvotes: 1

Views: 512

Answers (3)

DataGirl
DataGirl

Reputation: 439

I believe that both of the above answers will work, but since you don't need the data and you just need the format, I would do the following:

select * into new_table from table

TRUNCATE new_table; -- I'm sure you know this, but just in case someone is new and doesn't, truncate leaves the table structure and removes all of the data.

Upvotes: 0

Carlos Gutiérrez
Carlos Gutiérrez

Reputation: 14272

select * into new_table from table where 1 = 0

Upvotes: 5

adopilot
adopilot

Reputation: 4500

select * into new_table from table

Thats works in SQL2005

Upvotes: 2

Related Questions