Hello. Some of you might have already encountered this and some will encounter it in SQL interviews. Here is the solutions for the questions an interviewer might ask you. That is, how to copy or migrate one table's content to another table within a database or across databases.
Copy Table Data with in Database
Let us take a database. Here iShrissDB is my database with a table UserDetails that is to copied.
- select * into newTable Name from oldTable Name
For example:
![]()
- use iShrissdb
- select * into dbo.Details from dbo.UserDetails
![]()
Then:
Copy Table Data across two Databases
- select * into [new Database].newTable from [old database].oldTable
Let us take the two databases iShrissDB and DBEngine. As we can see we have a table named UserDetails in the iShrissDB database, we will copy this table from the iShrissDB database to the DBEngine database.
![]()
- use iShrissdb
- select * into [DBEngine].dbo.newTable from [iShrissdb].dbo.UserDetails
![]()
Copying Table with same Table name.
- select * into [DBEngine].[dbo].UserDetails from [iShrissdb].[dbo].UserDetails
![]()
Summary
We learned how to navigate a table within SQL Server databases.
Kudos!