Monday, January 24, 2011

Insert value from one Database Table to another Database Table


In this post i have explained how to insert value from one database to another database table.

i have created two tables one in master database another one in sample database
in master table EmpId is identity column,

Here i am getting identity(EmpId) value from Employee table of master database.
Here is the query.

use master
declare @EmpID int
insert into Employee(EmpName,DeptId) values('AAA',1)
set @EmpID=@@Identity
use sample
insert into EmpDetails(EmpId,Location,Email) Values(@EmpID,'Hyderabad','aaa@gmail.com')

No comments:

Post a Comment