Swap the Values of Two Columns in SQL Server

Swap the Values of Two Columns in SQL Server

24 Jul 2025
Intermediate
11.7K Views
4 min read
Learn with an interactive course and practical hands-on labs

Free SQL Server Online Course with Certificate - Start Today

Swapping Values of Columns in SQL Server: An Overview

Suppose you want to swap the values of two columns of a table in SQL Server, how could you achieve this tricky task? It is simple and so funny.

💡 Learn cool SQL tricks like this in our SQL Server Free Course With Certificate — sharpen your skills and get certified today!

Read More - Top 50 SQL Interview Questions And Answers

Read More: SQL Server Interview Questions and Answers

How to Swap Values of Two Columns of a Table in SQL Server?

Suppose you have a Customer table in the database with the following data and you want to interchange the values of columns, Name and Address then how do you do it?

Read More: Basics of SQL Commands


 SELECT * FROM CUSTOMER 

Output

Don't worry, to do this task, you need to just write a simple update query for the Customer table like as:


 UPDATE Customer SET Name=Address , Address=Name 

Now after query execution, you will find that the values of columns, Name, and Address have been interchanged, that's so cool.


SELECT * FROM CUSTOMER
 

Output

Note

  1. The data type of both columns should be the same and also the length should be enough to hold the swapped column data the data will be truncated.

Read More - Commonly Asked DBMS Interview Questions

What do you think?

I hope you will enjoy this trick while having fun with SQL Server. I would like to have feedback from my blog readers. If you want to gain a practical understanding, you can enroll in our SQL Server Course.

Do you Know?

.NET is gaining popularity day by day, especially after the release of .NET 8. .NET 8 is not only a framework version but much more than that. It redefines the way software applications are built and deployed, enabling developers to meet the evolving demands of modern computing.

Therefore, if you want to upskill yourselves and stand out from others consider our following training programs on .NET.

Take our Sqlserver skill challenge to evaluate yourself!

In less than 5 minutes, with our skill challenge, you can identify your knowledge gaps and strengths in a given skill.

GET FREE CHALLENGE

Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at ScholarHat)

He is a renowned Speaker, Solution Architect, Mentor, and 10-time Microsoft MVP (2016–2025). With expertise in AI/ML, GenAI, System Design, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development, he bridges traditional frameworks with next-gen innovations.

He has trained 1 Lakh+ professionals across the globe, authored 45+ bestselling eBooks and 1000+ technical articles, and mentored 20+ free courses. As a corporate trainer for leading MNCs like IBM, Cognizant, and Dell, Shailendra continues to deliver world-class learning experiences through technology & AI.
Live Training - Book Free Demo
ASP.NET Core Certification Training
31 Aug
08:30PM - 10:30PM IST
Checkmark Icon
Get Job-Ready
Certification
Advanced Full-Stack .NET Developer with Gen AI Certification Training
31 Aug
08:30PM - 10:30PM IST
Checkmark Icon
Get Job-Ready
Certification
Azure AI & Gen AI Engineer Certification Training Program
02 Sep
08:30PM - 10:30PM IST
Checkmark Icon
Get Job-Ready
Certification
Azure AI Engineer Certification Training
02 Sep
08:30PM - 10:30PM IST
Checkmark Icon
Get Job-Ready
Certification
Azure AI Foundry Certification Training
06 Sep
07:00AM - 09:00AM IST
Checkmark Icon
Get Job-Ready
Certification
Accept cookies & close this