Add new column to existing table
Here are the steps to add a new column to an existing table in various databases:
MySQL
ALTER TABLE table_name
ADD COLUMN new_column_name data_type;
Example:
ALTER TABLE customers
ADD COLUMN email VARCHAR(255);
PostgreSQL
ALTER TABLE table_name
ADD COLUMN new_column_name data_type;
Example:
ALTER TABLE customers
ADD COLUMN email VARCHAR(255);
Microsoft SQL Server
ALTER TABLE table_name
ADD new_column_name data_type;
Example:
ALTER TABLE customers
ADD email VARCHAR(255);
Oracle
ALTER TABLE table_name
ADD (new_column_name data_type);
Example:
ALTER TABLE customers
ADD (email VARCHAR2(255));
SQLite
ALTER TABLE table_name
ADD COLUMN new_column_name data_type;
Example:
ALTER TABLE customers
ADD COLUMN email TEXT;
Note:
table_name
is the name of the table you want to add the new column to.new_column_name
is the name of the new column you want to add.data_type
is the data type of the new column (e.g.VARCHAR(255)
,INT
,DATE
, etc.).
Before adding a new column, make sure to backup your database to avoid any data loss or corruption.