Removes rows from a table.
delete [top unsigned_integer] [from] [[database.]owner.]{view_name|table_name} [where search_conditions] [plan "abstract plan"]
delete [[database.]owner.]{table_name | view_name} [from [[database.]owner.]{view_name [readpast]| table_name [(index {index_name | table_name} [prefetch size][lru|mru])]} [readpast] [, [[database.]owner.]{view_name [readpast]| table_name [(index {index_name | table_name} [prefetch size][lru|mru])] [readpast]} ...] [where search_conditions]] [plan "abstract plan"]
delete [from] [[database.]owner.]{table_name|view_name} where current of cursor_name
When using prefetch and designating the prefetch size (size), the minimum is 2K and any power of two on the logical page size up to 16K. prefetch size options, in kilobytes, are:
Logical Page Size |
Prefetch Size Options |
---|---|
2 |
2, 4, 8 16 |
4 |
4, 8, 16, 32 |
8 |
8, 16, 32, 64 |
16 |
16, 32, 64, 128 |
The prefetch size specified in the query is only a suggestion. To allow the size specification, configure the data cache at that size. If you do not configure the data cache to a specific size, the default prefetch size is used.
To configure the data cache size, use sp_cacheconfigure.
delete authors
delete from authors where au_lname = "McBadden"
delete titles from titles, authors, titleauthor where authors.au_lname = 'Bennet' and authors.au_id = titleauthor.au_id and titleauthor.title_id = titles.title_id
The pubs2 database includes a trigger (deltitle) that prevents the deletion of the titles recorded in the sales table; drop this trigger for this example to work.
delete titles where current of title_crsr
delete authors where syb_identity = 4
delete from authors from authors readpast where state = "CA"
delete stores from stores readpast, authors where stores.city = authors.city
In pre-12.5.2 versions of SAP ASE, queries that used update and delete on views with a union all clause were sometimes resolved without using worktables, which occasionally lead to incorrect results. In SAP ASE 12.5.2 and later, queries that use update and delete on views with a union all clause are always resolved using worktables in tempdb.
The index, prefetch, and lru | mru options override the choices made by the SAP ASE optimizer. Use these options with caution, and always check the performance impact with set statistics io on. See Using the set statistics Command in Performance and Tuning Guide: Monitoring and Analyzing.
You can define a trigger to take a specified action when a delete command is issued on a specified table.
ANSI SQL – Compliance level: Entry-level compliant. The use of more than one table in the from clause and qualification of table name with database name are Transact-SQL extensions.
readpast is a Transact-SQL extension.
If set ansi_permissions is on, you must have select permission on all columns appearing in the where clause, in addition to the regular permissions required for delete statements. By default, ansi_permissions is off.
The following describes permission checks for delete that differ based on your granular permissions settings.
Setting | Description |
---|---|
Enabled | With granular permissions enabled, you must be the table or view owner, or a user with delete permission, or a user with delete any table permission. |
Disabled | With granular permissions disabled, you must have delete permission, be the table owner, or a user with sa_role. |
Values in event and extrainfo columns of sysaudits are:
Information | Values |
---|---|
Event | 18 |
Audit option | delete |
Command or access audited | delete from a table |
Information in extrainfo |
|
Information | Values |
---|---|
Event | 19 |
Audit option | delete |
Command or access audited | delete from a view |
Information in extrainfo |
|