Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagesql
CREATE TABLE Person (id INT, name VARCHAR(32), lastname VARCHAR(32), taxid int);

ALTER TABLE Person ADD COLUM
NCOLUMN residence VARCHAR(2) DEFAULT "GB";

ALTER TABLE Person DROP COLUMN lastname, taxid;

ALTER TABLE Person ADD COLUMN lastname DEFAULT "N/A";

This sequence of modifications will result in the following schema history

IDColumnsDelta
1id, name, lastname, taxidN/A
2id, name, lastname, taxid, residence+ residence ("GB")
3id, name, residence-lastname, -taxid
4id, name, residence, lastname+lastname ("N/A")

With this history, upgrading a tuple (1, "John", "Doe") of version 1 to version 4 means erasing columns lastname and taxid and adding columns residence with default "GB" and lastname (the column is returned back) with default "N/A" resulting in tuple (1, "John", "GB", "N/A").

...