Thursday, November 13, 2008

Insert Select function:Insert Data From One Database to Another Database in sql

Hi,
Here is the Query to insert the value from a table form one database in to a table in other database if the table is created manually

Insert into database1.dbo.TableName(FieldName1,FieldName2)Select FieldName1,FieldName2 from database2.dbo.TableName

For Ex :
Consider the DataBase Employee and Employee1
Now the Query will be

Insert into Employee.dbo.User(FirstName,LastName)Select FirstName,LastName from Employee1.dbo.User

It Fetches the Record from Employee1 and copy in to Employee

Here is the Query to create the table as same type and insert the values too

Select * into DatabaseName.dbo.NewTableName from DatabaseName.dbo.OldTableName(i.e the value from the table to be copied)

Ex:
Select * into
Employee1.dbo.User from Employee.dbo.User

No comments: