Introduction
In this tutorial, we want to modify an existing table by using a SQL Statement. In order to do this, we use the ALTER TABLE Statement.
We have already created a table called student.
The table has the following columns:
Example 1 - ADD COLUMN
We want to add a new column called "country" to the table student.
We navigate to the table student, open the Query Tool and execute the following SQL statement:we want to add the column "country" to the table student.
ALTER TABLE student
ADD country VARCHAR(50);
We can see that the column "country" has been successfully added.
Example 2 - RENAME COLUMN
Next, we want to rename the column "country" to "city".
We navigate to the table student, open the Query Tool and execute the following SQL statement:
ALTER TABLE student
RENAME COLUMN country TO city;
We can see that the column "country" has been successfully renamed to "city".
Example 3 - DROP COLUMN
Now, we want to delete the column "city".
We navigate to the table student, open the Query Tool and execute the following SQL statement:
ALTER TABLE student
DROP COLUMN city;
We can see that the column "city" has been successfully deleted.
Conclusion
Congratulations! Now you are one step closer to become an AI Expert. You have seen that it is very easy to modify a table with the ALTER TABLE Statement. Try it yourself!
Also check out our Instagram page. We appreciate your like or comment. Feel free to share this post with your friends.