Copy table

select * into employee1  from employee where id=5

select * into employee1  from employee

//CREATE NEW TABLE AND COPY ALL THE TABLE CONTENT

select * from employee1

drop table employee1

SELECT *
INTO employee1
FROM employee
WHERE 1=2

//ONLY COPY STRUCTURE

INSERT INTO employee1 (empname, address)
SELECT empname, address
FROM employee
WHERE id = 2


select * into <destination table> from <source table>


Example:

Select * into employee_backup from employee

 We can also select only a few columns into the destination table like below

select col1, col2, col3 into <destination table>

from <source table>




Example:


Select empId, empFirstName, empLastName, emgAge into employee_backup

from employee

Use this to copy only the structure of the source table.
select * into <destination table> from <source table> where 1 = 2



Example:

select * into employee_backup from employee where 1=2

Use this to copy a table across two database in the same Sql Server.
select * into <destination database.dbo.destination table>

from <source database.dbo.source table>


Example:

select * into Mydatabase2.dbo.employee_backup

from mydatabase1.dbo.employee