How to Add Column in the Table in SQLIn this section, we shall learn how to add a column in the table in Structured Query Language. The ALTER command in SQL allows the database users to add one or more columns in the SQL table. It allows the database users to modify the structure of the existing table in the database. The syntax for adding a Single Column from the table is given below: The syntax for deleting Multiple Columns from the table is given below: We have to use the ADD keyword in the ALTER command for adding one or more columns in the table. If you want to add a column in the table, you have to follow the following steps one by one in a given order:
Now, we are going to explain the above steps with an example: Step 1: Create a DatabaseIn the Structured Query Language, creating a database is the first step for storing the structured tables in the database. Use the below SQL syntax to create a database: Suppose you want to create the Vehicles database. For this, you have to type the following command in Structured Query Language: Step 2: Create a Table and Insert the dataNow, you have to use the below SQL syntax for creating the table in your database: Suppose you want to create the Cars table in the Vehicles database. For this, you have to type the following query in your SQL application: Step 3: View the Table Structure before Column AdditionAfter table creation and data insertion, you can view the structure of the Cars table by typing the following query in your SQL application:
Step 4: Add a Single Column to the tableThe following ALTER query in SQL, adds the average column to the above Cars table: Step 5: View the Table Structure after Column AdditionTo check the result of the query executed in the 4th step, you have to type the following command in SQL:
As we can see in the above output, one column has been successfully added to the Cars table. Add Multiple Columns to the tableThe following ALTER query in SQLadds the multiple columns to the above Cars table: To check the result of the above query, you have to type the following DESCRIBE or DESC Command in your SQL application:
As we can see, Engine_Number and Car_Number columns have been successfully added to the Cars table. Next TopicHow to Delete one row in SQL |