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.