sql delete statement

SQL Basic

homeBack

SQL DELETE Statement

  • The DELETE statement is used to delete rows in a table.

  • SQL DELETE Syntax:

    ” DELETE FROM table_name
    WHERE some_column=some_value
     ”

  • DELETE Statement Example:

    Table Name ” emp”

    S.no Name1 Name2 City
    2458 Peter Jhon Hyderabad
    4857 Faran Khan Hyderabad
    5874 Raj Kiran London
    8578 Sameer Ali Mumbai
    2213 Mark Rio New York

    we want to delete the person “Mark, Rio” in the “emp” table. 

    We use the following SELECT statement: 

    ” DELETE FROM Persons
    WHERE Name2=’Rio’
    AND Name1=’Mark’
     ”

    Result:

    S.no Name1 Name2 City
    2458 Peter Jhon Hyderabad
    4857 Faran Khan Hyderabad
    5874 Raj Kiran London
    8578 Sameer Ali Mumbai
    4213 Rahul Shah Dubai

  • Delete All Rows

    It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact. 

    ” DELETE FROM table_name

    or 

    DELETE * FROM table_name ”

    Note: Be very careful when deleting records. You cannot undo this statement!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s