Rename a Column Oracle

Midterms “season” has begun at university. So far 1 down (databases) few more to go this week and over the coming weeks. I already got the result of my databases midterm, it was way better than I expected.

I thought I had lost more than 2 points (yes I was 2 points short of a full mark :-P), especially in a the fill in the blanks part where I kept thinking “this should be filled here, oh wait no this looks similar as well, maybe its here, maybe here?…”

The exam had a practical part where we had to use Oracle, create some tables and run some queries. I am glad it was open book (no searching online, only using files available for the course), because when I tried to run some queries from the top of my head I had messed up with the syntax or ordering of clauses.

However, with so many slides and documents available I couldn’t find a way to rename an attribute or field. The only document that was close mentioned that it was not implemented before Oracle 9i (in the past you had to create a new column using the new name and copy over the data from the old to the new). (Un)Luckily for me, we had 9i installed so the feature exists, but the document was written for older version of Oracle…

After going back home and doing a quick search I found what I had to do:

ALTER TABLE tableName RENAME COLUMN oldColumn TO newColumn

Now I know ;-)!

Leave a Reply