



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The SQL ALTER command is utilized for modifying table structures, including adding or renaming columns, changing column datatypes, and dropping columns. syntax and examples for various ALTER command uses, such as adding a single column, adding multiple columns, adding a column with a default value, modifying an existing column, and renaming or dropping columns.
Typology: Assignments
1 / 5
This page cannot be seen from the preview
Don't miss anything!




alter command is used for altering the table structure, such as, to add a column to existing table to rename any existing column to change datatype of any column or to modify its size. to drop a column from the table.
Using ALTER command we can add a column to any existing table. Following is the syntax, ALTER TABLE table_name ADD( column_name datatype); Here is an Example for this, ALTER TABLE student ADD( address VARCHAR( 200 ) ); The above command will add a new column address to the table student , which will hold data of type varchar which is nothing but string, of length 200.
Using ALTER command we can even add multiple new columns to any existing table. Following is the syntax, ALTER TABLE table_name ADD( column_name1 datatype1, column-name2 datatype2, column-name3 datatype3); Here is an Example for this, ALTER TABLE student ADD( father_name VARCHAR( 60 ), mother_name VARCHAR( 60 ), dob DATE); The above command will add three new columns to the student table
Here is an Example for this, ALTER TABLE student MODIFY( address varchar( 300 )); Remember we added a new column address in the beginning? The above command will modify the address column of the student table, to now hold upto 300 characters.
Using ALTER command you can rename an existing column. Following is the syntax, ALTER TABLE table_name RENAME old_column_name TO new_column_name; Here is an example for this, ALTER TABLE student RENAME address TO location; The above command will rename address column to location.
ALTER command can also be used to drop or remove columns. Following is the syntax, ALTER TABLE table_name DROP( column_name); Here is an example for this, ALTER TABLE student DROP( address); The above command will drop the address column from the table student.