0% completed
ALTER
In SQL, the ALTER
statement is used to modify the structure of an existing database object, such as a table.
It allows you to add, modify, or drop columns, constraints, or other elements of a table without having to drop and recreate the entire table.
The basic syntax for the ALTER
statement varies depending on the specific modification you want to make. Here are some examples.
Adding a column
To add a new column in a database table, you can use the ALTER command like this
ALTER TABLE table_name ADD column_name data_type;
This statement adds a new column with the specified name and data type to the existing table.
Example
Suppose we have an employees table with the column id,
firstName,
lastName
as shown below:
by using ALTER, we can add a new column salary
like this:
ALTER TABLE Employees ADD salary INT;
After the query execution the Employee
table will look like this:
.....
.....
.....
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible