How to import data from a table in a database to a table in other databae in MS SQL Sever

In this article, I would like to share how to import data from a table in a database to a table in other database in Microsoft SQL Server.

 Introduction 

        I have two databases, Product and SaleProduct. I want to import data from a table ( Tbl_Category) in Product to other table (Tbl_ProCategory) in SaleProduct. First, I need to create a new Query and then write code on it to do this task. 
Now time to create a Query. Right click on Server name in Object Explorer panel --> Choose New Query. See picture below:
Create a new query
Create a new query
Syntax: 


INSERT [Database_name]..[Table_name]([Field_1],[Field_2])
SELECT [Field_1],[Field_2] FROM [Database_name]..[Table_name]
Example: 

INSERT [SaleProduct]..[Tbl_ProCategory]([Cate_ID],[Category_name])
SELECT [cateID],[cateName] FROM [Product]..[Tbl_Category]


After finished coding, click on Execute or press Ctrl + F5 to produce a query. 

Done....hope this post is helpful for you..:)
How to import data from a table in a database to a table in other databae in MS SQL Sever How to import data from a table in a database to a table in other databae in MS SQL Sever Reviewed by BeiLover on 10:37 PM Rating: 5

No comments:

Powered by Blogger.