Search code snippets, questions, articles...

Add columns, alter table SQL query

An SQL query is a query that is used to alter a table. This query is used to add columns to a table, alter the data type of a column, or to change the name of a column.
    Column_name1 data_type, 
    Column_name2 data_type (size)

ALTER table SQL query is used for adding new columns, constraints, and indexes to a table which already exists in the database. It is also used for changing the behavior of columns of a table.

For example, if you want to add a new column named 'Address' in the 'Employee' table, you can execute below SQL query for that.

ALTER TABLE Employee ADD COLUMN Address varchar(255)
ALTER TABLE Employee ADD(Address varchar(255))

Modifying existing column


ALTER TABLE table_name MODIFY (column_name new_data_type(new_size));


ALTER TABLE Employee MODIFY (Address varchar(255));

Removing column from table

ALTER query can be used to remove a column from the table using below command

ALTER TABLE table_name DROP COLUMN column_name;

Search Index Data (The code snippet can also be found with below search text)

add column sql
Was this helpful?
Programming Feeds
Learn something new everyday on Devsheet