find and solve || findandsolve.com
Please wait.....

Insert one table data to another table using sql || one database table to another database table

Insert one table data to another table using sql || one database table to another database table

In the SQL Server INSERT INTO SELECT statement is copies data from one table and inserts it into another table and the INSERT INTO SELECT statement requires that the data types in source and target tables matches.

I have created two Table named ParentInfo and Guardian like Id, FirstName, LastName,Address and so on. I want to copy the table ParentInfo to Table to Guardian.All the rows are insert another table using INSERT INTO statement.The rows of another table will be fetched based on one different criteria using SQL SELECT statement.

INSERT INTO
     Guardian(
  FirstName,
  LastName,
  Address
  )
  SELECT
   FirstName,
   LastName,
   Address
   FROM
   ParentInfo

Insert one table data into another using ORDER BY 

    INSERT INTO
     Guardian(   FirstName,   LastName,   Address   )   SELECT    FirstName,    LastName,    Address    FROM    ParentInfo    ORDER BY <COLUMN_NAME) DESC

Insert one dadatabae table values into another database table 

Assumption in the given above table ParentInfo is a from database and Guardian table is another to database.

SELECT * INTO todatabase.dbo.Guardian FROM  fromdatabase.dbo.ParentInfo

In another method

  1. Open SQL Server Management Studio.
  2. Right-click on the database name, then select Tasks > "Export data..." from the object explorer



3.  The SQL Server Import/Export wizard opens; click on "Next".



4.  Provide authentication and select the source from which you want to copy the data; click "Next".



5.  Specify database where you to copy the data to; click on "Next"



6.Select Source Tables and Views





Selena  Kandakar

Selena Kandakar

I like working on projects with a team that cares about creating beautiful and usable interfaces.

Comments



Report Response