Sql - ALTER and DROP TABLE
Code Life
By Pierre Marsaa
Adding a column
Tables change. ALTER TABLE … ADD COLUMN adds a column to an existing table; the rows already there get NULL in it:
↗️
Loading editor...
↶
↷
With a DEFAULT, the existing rows get that value instead of NULL:
↗️
Loading editor...
↶
↷
NOT NULL needs a DEFAULT here
You cannot add a NOT NULL column without a DEFAULT to a table that already has rows: the database would have nothing to put in them.
Verify