Csa 5
Csa 5
STATEMENTS
DELETE
This statement is used to delete row/s ( record/s) from
a given table.
With WHERE clause it will delete only those records which are
satisfying a given condition and without ‘WHERE’ clause it will
delete all the records from the table.
This statement will not delete a structure of a table.
➢mysql> DELETE FROM employees WHERE emp_no = 10;
➢ To delete all the rows from a table.
➢mysql> DELETE FROM employees;
DELETE
To delete record of Roll Number 4 in table STUDENT:
DROP
This statement is used to delete databases, tables from a
databases or columns from a table.
To delete database office.
mysql> DROP database office;
To delete table employees.
mysql> DROP TABLE employees;
To delete column (age) from a table student.
mysql> ALTER TABLE student DROP age;
DIFFERENCE BETWEEN DROP AND
DELETE
Drop Delete
Is used to either delete the Is used to delete a row or
table or any column in the rows of data in the table.
table. Example: DELETE FROM PAY;
Example: DROP TABLE Ex: DELETE FROM PAY where
employees; emp_id=4;
EX: ALTER TABLE STUDENT
DROP age;
ALTER TABLE STATEMENT
ALTER TABLE STATEMENT
Alter table statement is used to add, modify and delete columns. i.e.
To make changes in the structure of the table. It is also used to Rename
the table.
ADDING A COLUMN (ADD)
CHANGING COLUMN SIZE(MODIFY)
CHANGING COLUMN NAME(CHANGE)
DELETING A COLUMN (DROP)
DELETING/ ADDING PRIMARY KEY
RENAMING THE TABLE (RENAME)
25-08-2020 MEENA VAZIRANI
ADDING A COLUMN (ADD)
The ALTER statement is also used to ADD new columns with
respective data types to a table using the keyword ADD.