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 one table data into another using ORDER BY
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
- Open SQL Server Management Studio.
- 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