国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Database Mysql Tutorial drop,truncate與delete的區(qū)別

drop,truncate與delete的區(qū)別

Jun 07, 2016 pm 05:59 PM
delete drop truncate

這里說的delete是指不帶where子句的delete語句

注意:這里說的delete是指不帶where子句的delete語句
相同點
truncate和不帶where子句的delete, 以及drop都會刪除表內(nèi)的數(shù)據(jù)

不同點:
1. truncate和 delete只刪除數(shù)據(jù)不刪除表的結(jié)構(gòu)(定義)
drop語句將刪除表的結(jié)構(gòu)被依賴的約束(constrain),觸發(fā)器(trigger),索引(index); 依賴于該表的存儲過程/函數(shù)將保留,但是變?yōu)閕nvalid狀態(tài).
2.delete語句是dml,這個操作會放到rollback segement中,事務(wù)提交之后才生效;如果有相應(yīng)的trigger,執(zhí)行的時候?qū)⒈挥|發(fā).
truncate,drop是ddl, 操作立即生效,原數(shù)據(jù)不放到rollback segment中,不能回滾. 操作不觸發(fā)trigger.
3.delete語句不影響表所占用的extent, 高水線(high watermark)保持原位置不動
顯然drop語句將表所占用的空間全部釋放
truncate 語句缺省情況下將空間釋放到 minextents個 extent,除非使用reuse storage; truncate會將高水線復(fù)位(回到最開始).
4.速度,一般來說: drop>; truncate >; delete
5.安全性:小心使用drop 和truncate,尤其沒有備份的時候.否則哭都來不及
使用上,想刪除部分?jǐn)?shù)據(jù)行用delete,注意帶上where子句. 回滾段要足夠大.
想刪除表,當(dāng)然用drop
想保留表而將所有數(shù)據(jù)刪除. 如果和事務(wù)無關(guān),用truncate即可. 如果和事務(wù)有關(guān),或者想觸發(fā)trigger,還是用delete.
如果是整理表內(nèi)部的碎片,可以用truncate跟上reuse stroage,再重新導(dǎo)入/插入數(shù)據(jù)

通俗的講:

在實際應(yīng)用中,三者的區(qū)別是明確的。
當(dāng)你不再需要該表時, 用 drop;
當(dāng)你仍要保留該表,但要刪除所有記錄時, 用 truncate;
當(dāng)你要刪除部分記錄時(always with a WHERE clause), 用 delete.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the delete key on the keyboard? What is the delete key on the keyboard? Mar 16, 2023 pm 04:48 PM

There are two keyboard delete keys: del (delete) key and backspace key. Backspace is also called the backspace key. This key can delete the text content in front of the cursor; and the delete key can delete characters, files and selected objects. Each time you press the del key, a character to the right of the cursor will be deleted, and the character to the right of the cursor will move one frame to the left; when one or more files/folders are selected, press the Del key to quickly delete; in some applications Select an object in the program and press the Del key to quickly delete the selected object.

What is the function of delete key What is the function of delete key Mar 10, 2023 pm 06:07 PM

The functions of the delete key are: 1. Delete characters; each time the delete key is pressed, a character to the right of the cursor will be deleted, and the character to the right of the cursor will move one frame to the left. 2. Delete files; when one or more files/folders are selected, press the Delete key to quickly delete them (move to the Recycle Bin for recovery). 3. Delete the selected object; select an object in some applications and press the Delete key to quickly delete the selected object.

How to implement drag-and-drop sorting and drag-and-drop operations in uniapp How to implement drag-and-drop sorting and drag-and-drop operations in uniapp Oct 19, 2023 am 09:39 AM

Uniapp is a cross-platform development framework. Its powerful cross-end capabilities allow developers to develop various applications quickly and easily. It is also very simple to implement drag-and-drop sorting and drag-and-drop operations in Uniapp, and it can support drag-and-drop operations of a variety of components and elements. This article will introduce how to use Uniapp to implement drag-and-drop sorting and drag-and-drop operations, and provide specific code examples. The drag-and-drop sorting function is very common in many applications. For example, it can be used to implement drag-and-drop sorting of lists, drag-and-drop sorting of icons, etc. Below we list

How to Control + Alt + Delete: Mac Tutorial How to Control + Alt + Delete: Mac Tutorial Apr 16, 2023 pm 12:37 PM

Control+Alt+Delete: "Mac" mode Ctrlaltdel is a common key combination used by Windows users to open Task Manager. They usually exit unwanted applications from the manager menu to free up some space on their computer. The Control+Alt+Delete Mac variant lets you open the Force Quit menu. If Mac users want to quit the program causing the problem or view open programs, they can interact with the menu to investigate further. How to perform ControlAltDelete on Mac? If you have any malfunctioning applications, you must use this key combination to

Can't drop database 'database_name'; database doesn't exist - How to solve MySQL error: Can't drop database, database doesn't exist Can't drop database 'database_name'; database doesn't exist - How to solve MySQL error: Can't drop database, database doesn't exist Oct 05, 2023 am 11:46 AM

How to solve MySQL error: Unable to delete database, database does not exist Overview: MySQL is a commonly used relational database management system. When using MySQL, we often need to manage the database, including creating databases, deleting databases and other operations. However, when deleting a database, sometimes you will encounter the error message "Can'tdropdatabase'database_name';databasedoesn'texist", that is, you cannot delete it.

Deal | Tesla Model 3 Long Range AWD regains full $7,500 tax incentive, drops to below $40,000 Deal | Tesla Model 3 Long Range AWD regains full $7,500 tax incentive, drops to below $40,000 Jun 19, 2024 am 09:55 AM

Shortly after Tesla launched the Model 3 Highland refresh towards the end of last year, the US federal EV tax incentive rules changed, cutting the potential discount in half for eligible buyers because of Tesla's use of Chinese LFP cells in the new M

How to use PUT and Delete requests in SpringBoot How to use PUT and Delete requests in SpringBoot May 13, 2023 pm 12:16 PM

PUT and Delete requests are used in the Form form and only support get and post methods. In order to implement the put method, we can implement it through the following three steps: 1) Configure HiddenHttpMethodFilter in SpringMVC 2) Create a post form on the page 3) Create an input item, name ="_method", the value is the specified request method. Get the value of "_method" in the HiddenHttpMethodFilter class to get the new request method. The th tag is the thymeleaf template, which means that only when employee

Can deleted files be recovered? Can deleted files be recovered? Feb 24, 2023 pm 03:49 PM

Files deleted by delete can be recovered; because when users use delete to delete files, these files will be moved to the recycle bin and are not completely deleted. Recovery method: 1. Open the "Recycle Bin", select the file you want to restore, and click "Restore this item"; 2. Open the "Recycle Bin", select the file you want to restore, and use the undo shortcut "ctrl+z". Can.

See all articles