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:
In
previous articles I have explained
SQL: Copy full data of one
table to another using SQL command in SQL Database And 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 [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.