SQL ALTER TABLE Statement

The SQL ALTER TABLE statement is used to modify the structure of an existing table in a database. It allows you to add, modify, or delete columns, change the data type of columns, and add or delete constraints. ALTER TABLE is a powerful operation and is an important statement to know. It is commonly used to modify an existing table to meet changing needs or to fix errors in the table structure.

Syntax

ALTER TABLE table_name ADD column_name datatype;
ALTER TABLE table_name MODIFY column_name datatype;
ALTER TABLE table_name DROP column_name;
    

Example

ALTER TABLE customers ADD address VARCHAR(255);
ALTER TABLE customers MODIFY name VARCHAR(100);
ALTER TABLE customers DROP email;
    

This example adds a new column called "address" to the "customers" table, modifies the "name" column to have a maximum length of 100 characters, and deletes the "email" column from the table. These changes will be permanently applied to the table and can affect the performance of your queries.

You can learn more about SQL ALTER TABLE and other advanced topics in our SQL tutorials and references.