SQL -Structured Query Language - SQL Table - Alter - Add Column Tutorial
To add a column in the existing created table, then we can use an ' ALTER TABLE ' statement.
Syntax-
The basic syntax of ALTER TABLE statement to add a column in the existing table is given below –
ALTER TABLE table_name ADD (
colname1 colname1_datatype,
colname2 colname2_datatype,
…….
ColnameN colnameN_datatype
);
For example-
if we want to add
Column
- Username as a String - varchar(50) and Unique
- Status as an Integer - int and default 0
- Created_at as a String - date
In table user_detail
Then use the following syntax-
ALTER TABLE user_detail ADD (
username varchar(50) unique,
status int default 0,
created_at date
);
In Mysql Workbench-
This query or statement will add username, status, created_at column in the user_detail table.