Sunday, November 15, 2009

TRUNCATE Statement

  • Removes all rows from a table, leaving the table empty and the table structure intact
  • Is a data definition language (DDL) statement rather than a DML statement; cannot easily be undone
  • Syntax : TRUNCATE TABLE table_name;
  • Example : TRUNCATE TABLE copy_emp;

Saturday, November 14, 2009

DELETE Statement

You can remove existing rows from a table by using the DELETE statement :
  • DELETE [FROM] table [WHERE condition];
Deleting Rows from a Table :
Specific rows are deleted if you specify the WHERE clause :
  • DELETE FROM dept WHERE dname = 'Finance';
All rows in the table are deleted if you omit the WHERE clause :
  • DELETE FROM copy_emp;
Deleting Rows Based on Another Table :
  • Use subqueries in DELETE statements to remove rows from a table based on values from another table :
  • DELETE FROM emp WHERE deptno = (SELECT deptno FROM dept WHERE dname =‘SALES’);

Followers