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

Instruction

Excellent job. This time, suppose we have a table air_travel which looks like this:

CREATE TABLE air_travel (
  id integer PRIMARY KEY,
  code varchar(8),
  airplane varchar(16),
  operated_by varchar(32)
);

We want to rename this table to flight. How should we proceed?

Unfortunately, there is no single SQL standard for this task. In other words, to rename tables, different databases use different SQL code.

In Oracle, PostgreSQL, and MySQL, you can use:

ALTER TABLE air_travel RENAME TO flight;

Meanwhile, SQL Server uses a completely different syntax:

exec sp_rename 'plane_schema.air_travel', 'flight'

If you use any other database, check the proper syntax by reviewing its respective documentation.

In this course, we use the PostgreSQL engine, so you would use the first statement to rename a table.

Exercise

We've got the first draft of an updated table with stores. The table is named shop and has three columns: id, opened_on (a date column) and city.

The CEO has something specific in mind for the table names. He would rather use American words than British ones. So, your task is to rename table shop to store.

Note: use the PostgreSQL syntax to rename the table.

Stuck? Here's a hint!

Type:

ALTER TABLE shop RENAME TO store;