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’);

Friday, November 13, 2009

UPDATE Statement Syntax

Modify existing rows with the UPDATE statement :
  • UPDATE table SET column = value [, column = value, ...] [WHERE condition];
  • Update more than one row at a time (if required).
Updating Rows in a Table :

Specific row or rows are modified if you specify the WHERE clause :
  • UPDATE emp SET deptno = 40 WHERE empno = 7654;
All rows in the table are modified if you omit the WHERE clause :
  • UPDATE copy_emp SET deptno = 110;
Updating Two Columns with a Subquery :

  • Update employee 7654’s job and sal to match that of employee 7698
UPDATE emp SET job = (SELECT job FROM emp WHERE empno = 7698), sal = (SELECT sal FROM emp WHERE empno = 7698) WHERE empno = 7654;

Followers