Friday, February 4, 2011

REMOVING ROWS FROM A TABLE

    We can remove rows from a table using different ways. First of them is using DELETE command. It will remove row from a table. Using WHERE clause we specify which rows to be deleted. If we omit WHERE clause all rows from the table will be deleted.

    It is important to remember that DELETE command is a DML command and it can be rolled back. It means that if we want to remove rows permanently we need to COMMIT.

    Examples:

    clip_image001

    The DELETE command is not COMMITED yet, so we are able to undo it:

    clip_image002

    If we want to remove rows permanently, we should COMMIT

    clip_image003

    We can see that after DELETE command is committed, rollback won't be able to undo the changes.

    TRUNCATE TABLE

    This command will remove ALL ROWS from a table. It is important to remember that it can not be rolled back.

    Example:

    clip_image004

    If we want to remove whole table from a database ( rows, privileges, indexes), we need to use DROP command.

    clip_image005

    Rollback will again not undo changes made with DROP command.

    clip_image006

    Screen clipping taken: 4.2.2011 г.; 11:27 ч.

    There is way in Oracle 10g to undo "dropping table" using FLASHBACK.

    clip_image007

No comments:

Post a Comment