How to Copy Structure of One Table into Another Table?

SQL Query to copy structure of one table to another table in SQL Server.

Syntax: Select * into Newtable from Oldtable where 1=2

Ex: Select * into emp1 from emp where 1=2

The above query copies only structure(not data) of emp to emp1.

SQL Query to get structure of table

4 comments:

Anonymous said...

This query doesn't works because emp1 table doesn't exists.

Correct One is:

create table emp1 as select * from emp where 1=2;

-----
Thanks n regards
Nagalakshmi.

sqlqueries said...

Select * into emp1 from emp where 1=2

This query will work.even if emp1 table is not their after executing this query emp1 table will be created.

Check once again.

Anonymous said...

select * into emp1 from emp where 1=2
this query wroks ! thats cool trick..thanks !!!

Shilpa said...

Select * into emp1 from emp where 1=2

this query will not work for mysql as mysql does not support 'SELECT * INTO'.


Regards,
shilpa vk

Recent Posts