SQL: Copy full data of one table to another using SQL command in SQL Database.

Aman Sharma
0
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:


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:

 Select * from Bookcopy








New Table with name "
Bookcopy" has been created with same data and structure.


Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !