September 16th, 2008

DELETE

Posted by admin in E. INSERT, UPDATE, DELETE

Rows are DELETEd from the specified table when the condition statement is met.

DELETE all rows:             DELETE FROM table;

or

DELETE one or more rows:     DELETE FROM table
                              WHERE conditions;

> It is often convenient to test the WHERE clause with a SELECT statement to make sure the proper rows will be selected before using it in a DELETE.
> A subselect may be used to retrieve values for the WHERE clause.
> A subselect is a SELECT statement as described previously that has been attached to another SQL command.

September 15th, 2008

DELETE Syntax

Posted by admin in E. INSERT, UPDATE, DELETE

DELETE removes rows from a table.
The optional WHERE clause specifies which rows to delete.

               DELETE FROM table
               [WHERE conditions];

> DELETE removes rows from a table, but it does not delete the table’s definition.
Even if you delete all the rows in a table, the table still exists, but it is empty.
> DELETE has no column names, because it removes the entire row.
> DELETE without a WHERE clause deletes all the rows in the table. For this reason,
a delete without a where clause can be dangerous, because it is easy to do.
> Since the order of the rows is out of your control and is unimportant,
DELETE may reorder the rows. See ORDER BY to reorder your SELECTed data.
> To preserve referential integrity, the table definition can contain the action to be
taken when a row is deleted that has a FOREIGN KEY reference.

September 12th, 2008

UPDATE Syntax

Posted by admin in E. INSERT, UPDATE, DELETE

UPDATE does not add or delete rows, it only updates row data.
UPDATE without a WHERE clause will update all rows.
For this reason, you must be careful when doing an update.
The WHERE clause specifies the rows to be updated.

     UPDATE table
        SET column1 = [value,
                     | hostvariable,
                     | expression,
                     | NULL,
                     | specialregister,]
           [column2 = [value, ...
                     | hostvariable, ...
                     | expression, ...
                     | NULL, ...
                     | specialregister, ...]]
    [WHERE conditions];

> The SET value or expression must match the data type of the column and
replaces the existing value in that column.
> An expression can not cause an arithmetic error such as divide by zero.
> A value can not violate a CHECK constraint or a FOREIGN KEY constraint.

Next Page »

Store

Start your SQL Training now by ordering the Computer Based Training SQL Course
for $24.95.

Purchase Software For
$24.95