for example in my table i have domain and email columns, and data like this email column has something@Gmail.com and domain column has www.something .com i want to change domain column name to email name name if is this possible or not
Asked
Active
Viewed 1,383 times
-1
-
1please provide some sample data and explain along with it – TheGameiswar Jul 24 '16 at 09:51
-
Okay, I explained could you help me – sada Aug 06 '16 at 16:10
-
No, you need to be more explicit. Show your table structure, show 2-3 different sample records, and show the *same thing* but with the *same* records how you want them to look after the change. – Jeffrey Kemp Aug 07 '16 at 05:12
2 Answers
3
ALTER TABLE your_table RENAME COLUMN email TO email_temp;
ALTER TABLE your_table RENAME COLUMN domain TO email;
ALTER TABLE your_table RENAME COLUMN email_temp TO domain;

Gilad Green
- 36,708
- 7
- 61
- 95
-
SQL> create table hello (domain number(9),email number(8)); Table created. SQL> alter table hello rename column domain to email; alter table hello rename column domain to email * ERROR at line 1: ORA-00957: duplicate column name' – sada Jul 24 '16 at 10:14
-
Ya - That is why I first execute to change `email` into `email_temp` and then the rest. – Gilad Green Jul 24 '16 at 10:16
-
-
Sort answer no. Longer - [see this](http://stackoverflow.com/questions/23274679/renaming-multiple-columns-in-one-statement-with-postgresql) – Gilad Green Jul 24 '16 at 10:31
-
1@sada - why do you need a single "query"? What is wrong with running those three ALTER TABLE (not "queries", really) in succession? Why does the number of them matter? – Jul 25 '16 at 02:34
-
That is worked but if there is any possibility to change in single short to get the update – sada Aug 06 '16 at 16:13
-
-
You was given for me some "querys" to interchange the column name in table now I edited my question can please see the question again you can understand, and my final intention is if we can change the columns name in single query or not (is this possible say yes or no) if yes can please explain me – sada Aug 06 '16 at 16:26
1
Simple... you'll get the same effect simply by swapping the data:
UPDATE your_table SET email = domain, domain = email;
Plus, it will be done in one transaction.

Jeffrey Kemp
- 59,135
- 14
- 106
- 158
-
-
@sada - this is logically equivalent - in other words, you'll get the same **logical outcome** by swapping the *data* over instead of the *column names*. – Jeffrey Kemp Aug 06 '16 at 12:24
-
-suppose email column have something@gmail.com data and domain column www.sometimes.com what is the logical outcome there no sense to change swapping – sada Aug 06 '16 at 13:00
-
@sada, your question didn't convey that sense at all. So you want to only swap *a portion* of the column values? Please edit your question to make it clearer what your data looks like, and how you'd like it to look after the change. – Jeffrey Kemp Aug 06 '16 at 13:08
-
Thanks for suggestion, I will change that(you know my intention to the columns interchange and about my data) could you please help me to find the query – sada Aug 06 '16 at 16:04