We use cookies to enhance your experience on the site
CodeWorlds

ALTER TABLE and DROP TABLE - rebuilding a shelf

Shelves are not carved in stone. Over time they must be rebuilt: add a field, change a size, remove an unnecessary one. ALTER TABLE serves this purpose. And when an entire shelf becomes useless - DROP TABLE.

ALTER TABLE - adding a column

1ALTER TABLE ksiazki ADD COLUMN jezyk VARCHAR(20);

To the existing shelf

ksiazki
we added a new field
jezyk
. There is no need to build the table from scratch!

ALTER TABLE - changing a column's type

1ALTER TABLE autorzy MODIFY COLUMN imie VARCHAR(120);

The MODIFY COLUMN clause changes the type of an existing column - here we widen

imie
to 120 characters.

ALTER TABLE - dropping a column

1ALTER TABLE ksiazki DROP COLUMN jezyk;

DROP COLUMN removes the field together with its data. Careful - this cannot be undone!

ALTER TABLE - renaming the table

1ALTER TABLE recenzje RENAME TO opinie;

The RENAME TO clause changes the name of the whole shelf without touching its content.

DROP TABLE - removing the whole shelf

1DROP TABLE recenzje;

This command permanently removes the entire table together with all the scrolls. Use it with the utmost care - the shelf and everything on it disappear. The Keeper of the Catalog always thinks twice before giving such an order.

Go to CodeWorlds