SQL Alter Table

www.‮itfigi‬dea.com

In SQL, the ALTER TABLE command is used to modify an existing table. You can use this command to add, modify, or drop columns, change data types, rename tables, and more.

Here are a few examples of how to use the ALTER TABLE command:

  1. Adding a new column:
ALTER TABLE customers ADD address VARCHAR(100);

This will add a new column named address with a data type of VARCHAR(100) to the customers table.

  1. Modifying a column:
ALTER TABLE customers MODIFY address VARCHAR(150);

This will change the data type of the address column in the customers table from VARCHAR(100) to VARCHAR(150).

  1. Dropping a column:
ALTER TABLE customers DROP COLUMN address;

This will remove the address column from the customers table.

  1. Renaming a table:
ALTER TABLE customers RENAME TO clients;

This will rename the customers table to clients.

These are just a few examples of how you can use the ALTER TABLE command to modify an existing table. There are many other modifications that you can make using this command, depending on your specific needs.