delete 語句特殊用法

2021-04-09 02:47:22 字數 1287 閱讀 8370

示例

a. 不帶引數使用 delete

下例從 authors表中刪除所有行。

use pubs

delete authors

b. 在行集上使用 delete

因為 au_lname 可能不是唯一的,下例刪除其中的 au_lname 是 mcbadden 的所有行。

use pubs

delete from authors

where au_lname = 'mcbadden'

c. 在游標的當前行上使用 delete

下例顯示在名為 complex_join_cursor 的游標上所做的刪除。它只影響當前從游標提取的單行。

use pubs

delete from authors

where current of complex_join_cursor

d. 基於子查詢使用 delete 或使用 transact-sql 擴充套件

下例顯示基於聯接或相關子查詢從基表中刪除記錄的 transact-sql 擴充套件。第乙個 delete 顯示與 sql-92 相容的子查詢解決方法,第二個 delete 顯示 transact-sql 擴充套件。兩個查詢都基於儲存在 titles 表中的標題從 titleauthors 表中刪除行。

/* sql-92-standard subquery */

use pubs

delete from titleauthor

where title_id in

(select title_id

from titles

where title like '%computers%')

/* transact-sql extension */

use pubs

delete titleauthor

from titleauthor inner join titles

on titleauthor.title_id = titles.title_id

where titles.title like '%computers%'

e. 在 delete 和 select 中使用 top 子句

由於可以在 delete 語句中指定 select 語句,因此還可以在 select 語句中使用 top 子句。例如,下例從 authors 表中刪除前 10 個作者。

delete authors

from (select top 10 * from authors) as t1

where authors.au_id = t1.au_id

delete 語句特殊用法

a.不帶引數使用 delete 下例從authors表中刪除所有行。use pubs delete authorsb.在行集上使用 delete 因為au lname可能不是唯一的,下例刪除其中的au lname是 mcbadden 的所有行。use pubs delete from authors...

delete 刪除語句

delete 語句用於刪除表中的行。delete from 表名稱 where 列名稱 值 lastname firstname address city gates bill xuanwumen 10 beijing wilson fred zhongshan 23 nanjing fred wi...

delete 用法總結

delete 刪除 語法 boolean delete 資料 在當前作用域上刪除資料 用法 1,刪除陣列中的乙個元素 2,刪除乙個物件的屬性或方法 3,刪除乙個沒有用 var 宣告 變數 var arr 1,2,3,4 console.log arr console.log arr.length v...