The MySQL ALTER TABLE statement is used to add, modify, or drop/delete columns in a table. The MySQL ALTER TABLE statement is also used to rename a table.
The basic syntax is as follows:
| ALTER TABLE table_name ADD new_column_name column_definition [ FIRST | AFTER column_name ] |
| Employee | ||||
| Emp_id | Name | Surname | Salary | Dept_id |
| 1 | Rajesh | Khanna | 45000 | 2 |
| 2 | Sneha | Gupta | 55000 | 4 |
| 3 | Sandeep | Nehte | 95000 | 1 |
| 4 | Kirti | Patil | 25000 | 3 |
| 5 | Nilesh | Jadhav | 45000 | 3 |
| 6 | Dipesh | Das | 35000 | 5 |
| 7 | Kailash | Rane | 62000 | 1 |
| 8 | Kavita | Deshpande | 48000 | 3 |
| 9 | Sanjay | Datt | 50000 | 3 |
| 10 | Shruti | Hasan | 78000 | 1 |
Syntax For SQL:
| ALTER TABLE employee ADD COLUMN ( 'Mobile' varchar(100) NULL ); |
After Execute:
| (10 row(s) was affacted) (0 ms taken) |
Result:
| Emp_id | Name | Surname | Salary | Dept_id | Mobile |
| 1 | Rajesh | Khanna | 45000 | 2 | |
| 2 | Sneha | Gupta | 55000 | 4 | |
| 3 | Sandeep | Nehte | 95000 | 1 | |
| 4 | Kirti | Patil | 25000 | 3 | |
| 5 | Nilesh | Jadhav | 45000 | 3 | |
| 6 | Dipesh | Das | 35000 | 5 | |
| 7 | Kailash | Rane | 62000 | 1 | |
| 8 | Kavita | Deshpande | 48000 | 3 | |
| 9 | Sanjay | Datt | 50000 | 3 | |
| 10 | Shruti | Hasan | 78000 | 1 |
No comments:
Post a Comment