Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Modifying table structure
4. Changing column name
Adding NOT NULL constraints
Summary

Instruction

Perfect. We now know how to rename an entire table but what about renaming a single column? Our flight table contains a column named code which we want to rename to booking_ref. The syntax also differs from one database to another.

In PostgreSQL and Oracle, you would use:

ALTER TABLE flight RENAME COLUMN code TO booking_ref;

In MySQL, we also need to provide the column type:

ALTER TABLE flight CHANGE code booking_ref varchar(8);

In SQL Server:

exec sp_rename 'plane_schema.flight.code', 'booking_reg', 'COLUMN';

Let's check how the first syntax works in our PostgreSQL database.

Exercise

Great work so far. Now that the table has been named store, we've got another change to make. We think the opened_on column could have a better name.

Rename the column opened_on to opening_date in the store table.

Stuck? Here's a hint!

Type:

ALTER TABLE store RENAME COLUMN opened_on TO opening_date;