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

Instruction

Splendid work! Let's do a quick summary. In this part you've learned:

  • How to remove the table:
    DROP TABLE airplane_ticket;
  • How to add a column to a table:
    ALTER TABLE flight ADD COLUMN duration_minutes integer;
  • How to remove a column from a table:
    ALTER TABLE flight DROP COLUMN operated_by;
  • There is no standard syntax to rename a table or a column. In Oracle, PostgreSQL, and MySQL, you can use the ALTER TABLE syntax
    ALTER TABLE air_travel RENAME TO flight;
    ALTER TABLE flight RENAME COLUMN code TO booking_ref;
    Meanwhile, SQL Server uses a completely different syntax:
    exec sp_rename 'plane_schema.air_travel', 'flight'
    exec sp_rename 'plane_schema.flight.code', 'booking_reg', 'COLUMN';

Now, it's time for a pop quiz.

Exercise

Your task is to modify the structure of kitchen_setting table. It has the following columns: id (integer, primary key), customer_id (integer), area (integer) and address (varchar).

  1. Rename the area column to area_m2.
  2. Delete the customer_id column.
  3. Add the designer_id column of type integer.

Stuck? Here's a hint!

Type:

ALTER TABLE kitchen_setting RENAME COLUMN area TO area_m2;
ALTER TABLE kitchen_setting DROP COLUMN customer_id;
ALTER TABLE kitchen_setting ADD COLUMN designer_id INT;