Reputation: 81
how to create a duplicate table with no data in it
old tablename--student
newtablename--student1
plz tell me the exat query
thanks, Churchill..
Upvotes: 2
Views: 24708
Reputation: 1
In Sql Server you can right click on the table name in the Object Explorer.
Select "Script Table as" > "CREATE To" and then select "New Query Editor Window"
This creates a query to create the table.
In this case table name [student] change this to [student1] in the query and run and you have an exact copy of the schema, indexes, vartypes, primary keys etc.
Upvotes: 0
Reputation: 851
create table student1 as select * from student;
In the above query student1 is the table which has the exact copy of the already existing table student which copies the entire data.
create table student1 as select * from student where 0=1;
The query copies only the columns present in the student table but no data will be copied
But please note, you can't copy the constraints and indexes
Upvotes: 3
Reputation: 21
First you can copy the whole table by:
select * into (your_table_name) from student
After copying the whole table, you delete the data by running:
truncate table (your_table_name);
Upvotes: 2
Reputation: 1218
select * into student1 from student where 1=2
This will get you the columns, but indexes and other objects will require scripting with a database tool of some sort.
Upvotes: 1