Day 49 – SQL ADD Keyword
The SQL ADD keyword is used to add a new column or constraint to an existing table. The syntax for using the ADD keyword varies slightly between different SQL implementations, but the basic structure is as follows:
ALTER TABLE table_name ADD column_name data_type;
In this syntax,
ALTER TABLE is the SQL statement used to modify an existing table,
table_name is the name of the table being modified,
ADD is the keyword indicating that a new column or constraint is being added,
column_name is the name of the new column being added, and
data_type is the data type of the new column.
For example, to add a new column named
VARCHAR(255) to an existing table named
users, the following SQL query can be used:
ALTER TABLE users ADD email VARCHAR(255);
In addition to adding columns, the ADD keyword can also be used to add constraints such as PRIMARY KEY, FOREIGN KEY, CHECK, and UNIQUE constraints to an existing table. The syntax for adding constraints using the ADD keyword is similar, but with a slightly different syntax for each type of constraint.