SQL 使用 DELETE 語句刪除行

2021-04-13 22:42:24 字數 1138 閱讀 3362

delete 語句可刪除表或檢視中的一行或多行。delete 語法的簡化形式為:

delete table_or_view from table_sources where search_condition

table_or_view 指定要從中刪除行的表或檢視。table_or_view 中所有符合 where 搜尋條件的行都將被刪除。如果沒有指定 where 子句,將刪除 table_or_view 中的所有行。from 子句指定刪除時用到的額外的表或檢視及聯接條件,where 子句搜尋條件中的謂詞使用它們限定要從 table_or_view 中刪除的行。該語句不從 from 子句指定的表中刪除行,而只從 table_or_view 指定的表中刪除行。

任何已刪除所有行的表仍會保留在資料庫中。delete 語句只從表中刪除行,要從資料庫中刪除表,必須使用 drop table 語句。

使用 delete 語句刪除行

對於 northwind 資料庫中名為 lyngbysild 的公司所提供的產品,以下指令碼顯示了刪除與這些產品有關的行時所需要的三個 delete 語句。因為該指令碼涉及了從現有訂單中刪除行,所以它不是乙個典型的商業操作,但是它確實顯示了一系列複雜程度不同的刪除操作。

use northwind

godelete [order details]

from suppliers, products

where products.supplierid = suppliers.supplierid

and suppliers.companyname = 'lyngbysild'

and [order details].productid = products.productid

godelete products

from suppliers

where products.supplierid = suppliers.supplierid

and suppliers.companyname = 'lyngbysild'

godelete suppliers

where companyname = 'lyngbysild'

go

delete 刪除語句

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

Sqlite 刪除語句 Delete

sqlite 的 delete 語句用於刪除表中已有的記錄。可以使用帶有 where 子句的 delete 查詢來刪除選定行,否則所有的記錄都會被刪除。sqlite 要清空表記錄,只能使用delete來刪除全部表資料。但是與別的資料庫不同,sqlite在為表建立自增列後,會將表自增列的當前序號儲存到...

Sqlite 刪除語句 Delete

sqlite 的 delete 語句用於刪除表中已有的記錄。可以使用帶有 where 子句的 delete 查詢來刪除選定行,否則所有的記錄都會被刪除。sqlite 要清空表記錄,只能使用delete來刪除全部表資料。但是與別的資料庫不同,sqlite在為表建立自增列後,會將表自增列的當前序號儲存到...