第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

mysql delete語(yǔ)句刪除數(shù)據(jù)

標(biāo)簽:
MySQL

Summary: in this tutorial, you will learn how to use the MySQL DELETE statement to remove data from one ore more database tables.

To remove data from a table, you use the MySQL DELETEstatement. The MySQL DELETE statement allows you to remove records from not only one table but also multiple tables using a single DELETE statement.

MySQL delete from one table

To remove data from a single table, you use the following DELETE statement:

DELETE FROM table    [WHERE conditions] [ORDER BY ...] [LIMIT rows]

Followed the DELETE FROM clause is the table name that you want to delete records.

The WHERE clause specifies which rows you want to delete. If a record meets the WHERE condition, it is deleted permanently from the table. If you omit the WHERE clause, all records in the table are deleted.

The DELETE statement returns the number of rows deleted specified by the ROW_COUNT() function.

Notice that the ROW_COUNT() function returns the number of rows inserted, updated or deleted by the last INSERTUPDATE or DELETE statement

MySQL delete from a table examples

Suppose you want to remove employees whose officeNumberis 4, you use the DELETE statement with the WHEREclause as the following query:

DELETE FROM employees  WHERE officeCode = 4

To delete all employee records from the employees table, you use the DELETE statement without the WHERE clause as follows:

DELETE FROM employees

All employee records in the employees table were deleted.

MySQL delete from multiple tables

To delete records from multiple tables, you use one of the following DELETE statements:

DELETE table_1, table_2,... FROM table-refs    [WHERE conditions] DELETE FROM table_1, table_2,... USING table-refs [WHERE conditions]

Let’s examine each statement in greater detail:

  • Both DELETE statements delete records from multiple tables i.e., table_1table_2,… specified after the DELETE keyword.

  • The first DELETE statement uses the FROM clause while the second one use the USING clause.

  • The WHERE clause is used to determine which record to be deleted.

  • Both statements return the number of rows deleted from the multiple tables.

MySQL delete from multiple tables example

Let’s take a look at the offices and employees tables in the MySQL sample database.

mysql delete multiple tables offices employees

Suppose one office is closed and you want to remove all employee records in the employees table associated with that office and also the office itself in the offices table, you can use the second form of the MySQL DELETEstatement

The following query removes the office record with the code is 1 in the offices table and also all employee records associated with the office 1 in the employees table:

DELETE employees,     offices  FROM employees,   offices  WHERE employees.officeCode = offices.officeCode  AND        offices.officeCode = 1

You can verify the changes by using the following SELECT statements to query data from both employees table and offices table.

SELECT * FROM employees  WHERE officeCode = 1; SELECT * FROM offices WHERE officeCode = 1;

You can achieve the same effect by using the second form of the MySQL DELETE statement as follows:

DELETE FROM employees, offices  USING employees, offices  WHERE employees.officeCode = offices.officeCode  AND        offices.officeCode = 1

In this tutorial, you have learned various forms of the MySQL DELETE statement to delete records from one or more tables.

Related Tutorials

原文链接:http://outofmemory.cn/mysql/mysql-delete-statement

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消