Changing a table structure
Another basic SQL operation is to add or delete a column from a table. This can be done using the ALTER TABLE
syntax followed by the desired operation. The syntax for these operations is defined as follows.
To add a column named new
to the Employee
table:
ALTER TABLE Employee
ADD new;
To delete a column named old
from Employee
:
ALTER TABLE Employee
DROP COLUMN old
You have the task to add a new column Email
and drop the column Birthday
from the Person
table.
Cet exercice fait partie du cours
Hierarchical and Recursive Queries in SQL Server
Instructions
- Add the column
Email
toPerson
. - Delete the column
Birthday
fromPerson
.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
-- Add the column EMail to Person
___ ___ Person
___ ___ VARCHAR(255);
-- Delete the column Birthday of Person
___ ___ Person
___ ____ ___;
-- Check the table definition
SELECT *
FROM Person;