Introduction:
In
this article I will explain how to copy full data of one table to another new
table in SQL database. Some time we want to create a copy of table (with data),
then we can achieve this by using Following SQL command.
Description:
In
previous articles I have explained SQL:
How to Create table in SQL Database.? And SQL:
How to create Database in SQL server and SQL:
How to generate script of database in SQL Server and Asp.Net:
Bind or Populate Gridview control using Dataset and stored procedure .
Syntax:
Select * into New_Table_name from Source_table_name
|
In this query New_Table_name
is ouput table or can say destination table, where want to copy data from Source_table_name
Table.
We just give the name of
the output table and new table will be generated with data.
Example:
Suppose we have a table”Book”
CREATE TABLE [dbo].[Book](
[BookID]
[int] IDENTITY(1,1) NOT NULL,
[Book_name]
[varchar](50)
NULL,
[Author]
[varchar](50)
NULL,
[Description]
[varchar](500)
NULL,
PRIMARY KEY(BookID)
)
|
Insert Some data:
Now Execute
the following Sql Command
Select * into BookCopy from
Book
|
Result:
New Table with name "Bookcopy" has been created with same data and structure.