Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server 2016 (13.x) and later
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
SQL database in Microsoft Fabric
This topic describes how to copy columns from one table to another, copying either just the column definition, or the definition and data in SQL Server by using SQL Server Management Studio or Transact-SQL.
In This Topic
Before you begin:
To copy columns, using:
When you copy a column that has an alias data type from one database to another, the alias data type may not be available in the destination database. In such a case, the column will be assigned the nearest matching base data type available in that database.
Requires ALTER permission on the table.
Open the table with columns you want to copy and the one you want to copy into by right-clicking the tables, and then clicking Design.
Click the tab for the table with the columns you want to copy and select those columns.
From the Edit menu, click Copy.
Click the tab for the table into which you want to copy the columns.
Select the column you want to follow the inserted columns and, from the Edit menu, click Paste.
Follow the directions for copying column definitions above.
Note
Before you begin to copy data from one table to another, make sure that the data types in the destination columns are compatible with the data types of the source columns
Open a new Query Editor window.
Right-click the Query Editor, and then click Design Query in Editor.
In the Add Table dialog box, select the source and destination table, click Add, and then close the Add Table dialog box.
Right-click an open area of the Query Editor, point to Change Type, and then click Insert Results.
In the Choose Target Table for Insert Results dialog box, select the destination table.
In the upper portion of the Query Designer, click the source column in the source table.
The Query Designer has now created an INSERT query. Click OK to place the query into the original Query Editor window.
Execute the query to insert the data from the source table to the destination table.
In Object Explorer, connect to an instance of Database Engine.
On the Standard bar, click New Query.
Copy and paste the following example into the query window and click Execute.
USE AdventureWorks2022;
GO
CREATE TABLE dbo.EmployeeSales
( BusinessEntityID varchar(11) NOT NULL,
SalesYTD money NOT NULL
);
GO
INSERT INTO dbo.EmployeeSales
SELECT BusinessEntityID, SalesYTD
FROM Sales.SalesPerson;
GO
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Module
Create and manage columns within a table in Microsoft Dataverse - Training
Learn how to create and manage table columns in Dataverse.
Certification
Microsoft Certified: Azure Database Administrator Associate - Certifications
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.
Documentation
Duplicate tables without the row data. - SQL Server
Create a duplicate copy of a table, without the row data.
This article shows you how to modify columns using SQL Server Management Studio and Transact-SQL.
Change Column Order in a Table - SQL Server
Change Column Order in a Table