Sql - ALTER and DROP TABLE
📖 Read the lesson
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...
↶
▶️ Run
↷
With a
DEFAULT
, the existing rows get that value instead of
NULL
:
↗️
Loading editor...
↶
▶️ Run
↷
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