Practical 17 - Update Delete Alter Table
Practical 17 - Update Delete Alter Table
Update & Delete records / Add New Columns & Drop Existing Columns
update command - This command is used to change the contents of the table.
The Syntax of this command is as follows -
delete command - This command is used to change the contents of the table.
The Syntax of this command is as follows -
alter table – this command is used to change the structure of the table. i.e. to add a new
column or remove an existing column, Changing the name and/or data type of a
column.
Introduction – we are operating on college database having table staff. The staff table
contains the fields – tno,fname ,sname , post and salary.
mysql> use college;
Database changed
+-----+-----------+-----------+-----------+--------+
+-----+-----------+-----------+-----------+--------+
+-----+-----------+-----------+-----------+--------+
+-----+-----------+-----------+-----------+--------+
+-----+-----------+-----------+-----------+--------+
+-----+-----------+-----------+-----------+--------+
+-----+-----------+-----------+-----------+--------+
+-----+-----------+-----------+-----------+--------+
+-----+-----------+-----------+-----------+--------+
+-----+----------+-----------+-----------+--------+
+-----+----------+-----------+-----------+--------+
+-----+----------+-----------+-----------+--------+
+-----+----------+-----------+-----------+--------+--------+
+-----+----------+-----------+-----------+--------+--------+
+-----+----------+-----------+-----------+--------+--------+
+-----+----------+-----------+-----------+--------+
+-----+----------+-----------+-----------+--------+
+-----+----------+-----------+-----------+--------+
mysql> alter table staff add column gender varchar(5) after sname;
+-----+----------+-----------+--------+-----------+--------+
+-----+----------+-----------+--------+-----------+--------+
+-----+----------+-----------+--------+-----------+--------+
ERROR 1406 (22001): Data too long for column 'gender' at row 1
+-----+----------+-----------+--------+-----------+--------+
+-----+----------+-----------+--------+-----------+--------+
+-----+----------+-----------+--------+-----------+--------+
+-----+----------+-----------+--------+-----------+--------+
+-----+----------+-----------+--------+-----------+--------+
+-----+----------+-----------+--------+-----------+--------+