Copy only the structure of an existing table into new table with data /without data in SQL Server
In this article we learn that how to create new table from existing table in SQL Server means we copy structure an existing table to new table. Here we will discuss with two options:-
Copy only the structure of an existing table into new table (means without Data)
Copy only the structure of an existing table into new table
Here we have table with info_table name means existing table
Now we will create a new with new_info_table
So we have just need write blow syntax :-
select * into tblnew from tblold where 1=2
For out-put:-
select * into new_info_table from info_table where 1=2
Out-put:-
Copy only the structure with data of an existing table into new table
Here we have table with info_table name with some data
Now we will create a new with new_info_table with data
So we have just need write blow syntax:-
select * into tblnew from tblold
For out-put:-
select * into new_info_table from info_table
Out-put:-
Note :-
We can copy structure with/without data but we cannot copy any constraint like primary key ,
Copy only the structure of an existing table into new table with data /without data in SQL Server
Reviewed by NEERAJ SRIVASTAVA
on
5:17:00 PM
Rating:
No comments: