How to Rename a SQL Server Column or Change Its Excel Header
Question details
The user needs to know how to rename a column in SQL Server either permanently at the table level or temporarily so that exported Excel files have specific column headers.

- Product
- SQL Server / Excel
- Device & OS
- not provided
- Scenario
- Querying a database and exporting the SQL Server results to an Excel spreadsheet, requiring specific column names for the output.
- Observed behavior
- The user wants to display custom column names in query results and Excel exports without necessarily altering the underlying database schema, or needs the exact command to permanently rename the column.
Determine whether you need a permanent database change or a temporary display change. Ensure you have the necessary ALTER permissions on your database before attempting to permanently rename a SQL Server column, as schema changes may affect existing applications.
Use a SQL Alias to Change the Display Header for Excel Exports
The safest and most common way to change a column header for an Excel export without altering the database schema is by using an alias in your query.
Using a SQL alias allows you to rename the column temporarily in your query results. This is highly recommended when you only need a specific header name for your exported Excel file and want to avoid breaking database dependencies.
Open your SQL Server management tool (such as SQL Server Management Studio) and start a New Query window.
Type your SELECT statement and use the 'AS' keyword to define the alias. For example: SELECT datecompleted AS initialdatecompleted FROM dbo.TableName;
Click 'Execute' or press F5. The result grid will now display 'initialdatecompleted' as the column header instead of the original database name.
Right-click the query results, select 'Save Results As...' or 'Copy with Headers', and paste/save the output into your spreadsheet application. The spreadsheet will automatically use your defined alias as the column header.

Permanently Rename the SQL Server Column Using sp_rename
If the column name is incorrect at the database level and needs a permanent fix, you can use the built-in stored procedure.
Easily Format Your SQL Exports with WPS Spreadsheet
After exporting your SQL Server query results, use WPS Spreadsheet to open, manage, and manually adjust your column headers. It provides a seamless environment to format raw database data into polished, professional reports without altering your database.
- 1. Open your exported data: Launch WPS Office and click on 'Spreadsheet'. Navigate to 'Menu' > 'Open' and select the .csv or .xlsx file generated from your SQL Server query.
- 2. Adjust column headers: Click directly on the header cells in the first row. You can type new names, change font colors, or apply bold formatting to make your headers stand out.
- 3. Save your professional report: Go to 'Menu' > 'Save As' to keep your modifications in a fully compatible Microsoft Excel format, ready to be shared with your team.

Frequently Asked Questions
Can I undo a column rename made with sp_rename?
Yes, you can rename the column back to its original name by running the sp_rename command again, swapping the new name and old name in the query parameters.
Why does exporting SQL results to Excel drop my column headers?
When copying or saving to Excel, ensure that the option 'Include column headers when copying or saving the results' is enabled in your SQL Server management tool's settings. In SSMS, this can be found under Tools > Options > Query Results.
Does using an alias in SQL Server change the actual table?
No, using the 'AS' keyword to create an alias only changes the column name temporarily for that specific query's output. The underlying database table and its schema remain untouched.




