SQL: Copy data of table of one database to new table of other database in SQL Server.

Aman Sharma
0
In this article I will explain how to copy full data of one table of first database to another new table of second database in SQL database. Some time we want to create a copy of table (with data) of one database to another database, we can achieve this by using Following SQL command.

Description:


Syntax:

Select * into [Database2].[dbo].[New_Table_name] from [Database1].[dbo].[Source_table_name]

In this query  New_Table_name is ouput table in other database(destination Database), where we  want to copy data from Source_table_name Table of first database (Source database).
We just give the name of the output table and new table will be generated with data in second database.there is no need to create table manually.

Example:
Suppose we have a table”Book” in Database “Blog
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 to Copy data to Table “BookCopy “ of “DataBase_Name”

Select * into [DataBase_Name].[Dbo].[BookCopy] from [Blog].[dbo].[Book]


Result:

Select * from  [DataBase_Name].[Dbo].[BookCopy]







Table "BookCopy" will be created in database DataBase_Name after executing the above query.


Post a Comment

0Comments
Post a Comment (0)

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

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