Table : student_details
Query : ALTER Table student_details ADD Location varchar(20); |
Note : The values in column “Location” are left blank because had added the column to the table and not inserted the values in it. |
Example-2 : Modifying data type of column “Name” in the student_details table.
Query : ALTER Table student_details MODIFY COLUMN Name char(10); |
Output : You won’t see any change in view of table. But, while inserting new values, only character values will be inserted in the “Name” column.
Example-3 : Dropping a column “Marks” from student_details table.
Query : ALTER Table student_details DROP COLUMN Marks; |
Output :
Example-4 : Adding Primary Key in student_details table.
Query : ALTER Table student_details ADD CONSTRAINT C1 PRIMARY KEY (Roll_No); |
Output :
Note : A Primary Key is an attribute of a table with the help of which each data record present in the table can be uniquely identified. To know more about, please refer KEYS IN DBMS. |