1

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

3 Answers 3

5
select * into new_table from table where 1 = 0
Sign up to request clarification or add additional context in comments.

Comments

2

select * into new_table from table

Thats works in SQL2005

1 Comment

thanks for your reply, i need to create oly the table with the entire columns and not the datas. the fresh datas has to be into the new table.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.