Sql server: Insert multiple tables data into another table - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

Sql server: Insert multiple tables data into another table

In this article I am going to explain how to insert multiple tables data into one table in sql server.


Implementations:
I have created 2 tables Country and state, insert some dummy records into it. I want to insert country and state name into another table (countrystate).

Tb_Country
Id
int
CountryName
varchar(100)

Tb_State
Id
int
StateName
varchar(100)
CountryId_Fk
int

CountryState
CSId
int
Country
varchar(200)
Statename
varchar(200)
Recdate
date


Get the date from both table using join and insert into table.

Insert into CountryState(Country,Statename)
SELECT     dbo.Tb_State.StateName, dbo.Tb_Country.CountryName
FROM         dbo.Tb_Country INNER JOIN
                      dbo.Tb_State ON dbo.Tb_Country.Id = dbo.Tb_State.CountryId_Fk



What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+


EmoticonEmoticon