SQL Server series: Delete statements

Source: Internet
Author: User

Deleting data deletes some or all of the records in the table, and you can delete one or more records by specifying delete criteria when deleting. If you do not specify a delete condition, the DELETE statement deletes all records in the table and empties the data table.

Delete syntax:

[With <common_table_expression> [,... n] ]DELETE     [TOP (expression) [PERCENT] ]     [ from]{{Table_alias| <Object>       |rowset_function_limited[With (table_hint_limited [... n] ) ] }       | @table_variable    }    [<output clause>]    [From table_source [,... n] ]     [WHERE {<search_condition> | {[Current of {{[GLOBAL]cursor_name}|Cursor_variable_name}] }            }     ]     [OPTION (<query hint> [,... n] ) ] [; ]<Object>::={     [Server_name.database_name.schema_name. | database_name. [Schema_name] . |schema_name. ] Table_or_view_name}

1. Delete one or more records according to the specified criteria

DELETE  from [dbo]. [Product] WHERE = 1

2. Delete all records in the table

You can delete all records in a table by using a DELETE statement without a WHERE clause.

DELETE  from [dbo]. [Product]

Deleting all records in a table can also use the TRUNCATE statement:

TRUNCATE TABLE [dbo]. [Product]

3. Use TOP to limit the number of rows deleted

When the TOP (n) clause is used with the delete, the delete operation is performed on the randomly selected n rows.

DELETE TOP (tenfrom[dbo]. [Product]

SQL Server series: Delete statements

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.