How to copy tables in SQL Server

Asked By 0 points N/A Posted on -
qa-featured

Hi! I need to copy table with a lot of columns in SQL Database (mdf file), only structure without data and assign a new name to it. New table will have the same amount of columns only 2 of them will have different data types. Connected my database to SQL Server Management Tools but couldn't find an option of copying it. Please help. 

SHARE
Answered By 0 points N/A #184114

How to copy tables in SQL Server

qa-featured
HELLO
 
You can uses SELECT INTO statement for copy data from one table to another. And you can insert into the new table.
 
 
SELECT INTO STATEMENT
 
SQL SELECT INTO Syntax
 
 
You can copy columns in the new tables.
 
SELECT *
INTO newtable [IN externaldb]
FROM table1;
 
If you want to data one table to another then use this code.
 
SELECT empname.empnameName, Orders.OrderID
INTO empOrderBackup2013
FROM employee
LEFT JOIN Orders
ON employee.employeeID=Orders.employeeID;
 
 
 
The select into statement used for following:-  
1. Create new table
2. Empty table 
3. If you want return with no data then add WHERE. ex:-
 
SELECT *
INTO newtable
FROM table1
WHERE 1=0;
 

Related Questions