Example 1
Add an email column to an existing users table
The email column is added to the table. Existing rows receive NULL for the new column because no default was specified. Use UPDATE to populate the new column for existing rows.
Engine-specific syntax
Setup
CREATE TABLE users (id INT, name VARCHAR(50));
INSERT INTO
users (id, name)
VALUES
(1, 'Alice'),
(2, 'Bob');SQL
ALTER TABLE users
ADD COLUMN email VARCHAR(100);
SELECT
id,
name,
email
FROM
users
ORDER BY
id;| id | name | |
|---|---|---|
| 1 | Alice | NULL |
| 2 | Bob | NULL |
Engine-specific syntax
Setup
CREATE TABLE users (id INT, name VARCHAR(50));
INSERT INTO
users (id, name)
VALUES
(1, 'Alice'),
(2, 'Bob');SQL
ALTER TABLE users ADD email VARCHAR(100);
SELECT
id,
name,
email
FROM
users
ORDER BY
id;| id | name | |
|---|---|---|
| 1 | Alice | NULL |
| 2 | Bob | NULL |
SQL Server uses ADD without the COLUMN keyword. The resulting table state is identical across all engines.