Explanation of Truncate Table usage

Explanation of Truncate Table usage

TRUNCATE TABLE

Deletes all rows in a table without logging individual row deletions.

grammar

TRUNCATE TABLE name

parameter

name

Is the name of the table to be truncated or from which all rows are to be deleted.

Notes

TRUNCATE TABLE is functionally identical to a DELETE statement without a WHERE clause: both delete all rows in the table. However, TRUNCATE TABLE is faster than DELETE and uses fewer system and transaction log resources.

The DELETE statement deletes one row at a time and records an entry in the transaction log for each row deleted. TRUNCATE TABLE deletes data by freeing the data pages used to store table data, and only records the release of pages in the transaction log.

TRUNCATE TABLE deletes all rows in the table, but the table structure and its columns, constraints, indexes, etc. remain unchanged. The count value used to identify new rows is reset to the seed for the column. If you want to preserve the identity count value, use DELETE instead. If you want to remove a table definition and its data, use the DROP TABLE statement.

For tables referenced by a FOREIGN KEY constraint, TRUNCATE TABLE cannot be used. Instead, a DELETE statement without a WHERE clause should be used. Because TRUNCATE TABLE is not logged, it cannot activate triggers.

TRUNCATE TABLE cannot be used on a table that participates in an indexed view.

Example

The following example deletes all data from the authors table.

TRUNCATE TABLE authors

Permissions

TRUNCATE TABLE permissions default to the table owner, members of sysadmin fixed server role, and members of db_owner and db_ddladmin fixed database roles and are not transferable.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Oracle's implementation of granting user authorization to truncatetable
  • Difference between delete from table name and truncate table table name
  • Usage of Truncate in SQL
  • Detailed explanation of truncate log file in golang practice
  • Detailed usage of tf.truncated_normal and tf.random_normal
  • How to improve truncate in smarty to support Chinese
  • How to roll back TRUNCATE transactions in SQL Server
  • Understanding the difference between truncate and delete in SQL with examples
  • Detailed explanation of the similarities and differences between drop, delete and truncate in SQL
  • MySQL starts slow SQL and analyzes the causes

<<:  Vue implements tab navigation bar and supports left and right sliding function

>>:  How to solve the problem that VMware virtual machine bridge mode cannot access the Internet

Recommend

Basic principles for compiling a website homepage

1. The organizational structure of the hypertext d...

How to change the default character set of MySQL to utf8 on MAC

1. Check the character set of the default install...

CSS multi-level menu implementation code

This is a pretty cool feature that makes web page...

Vue uses the method in the reference library with source code

The official source code of monaco-editor-vue is ...

JavaScript uses setTimeout to achieve countdown effect

In order to enhance the ability to write JavaScri...

Do you know the common MySQL design errors?

Thanks to the development of the Internet, we can...

How to quickly clean up billions of data in MySQL database

Today I received a disk alarm exception. The 50G ...

Installation of mysql-community-server. 5.7.18-1.el6 under centos 6.5

Use the following command to check whether MySQL ...

About WeChat Mini Program to implement cloud payment

Table of contents 1. Introduction 2. Thought Anal...

Detailed introduction to deploying k8s cluster on centos7 system

Table of contents 1 Version and planning 1.1 Vers...

Detailed explanation of how to manually deploy a remote MySQL database in Linux

1. Install mysql Run the following command to upd...

Sample code for implementing dark mode with CSS variables

Recently, WeChat was forced by Apple to develop a...

Management of xinetd-based services installed with RPM packages in Linux

Table of contents Preface 1. Startup management b...

Sitemesh tutorial - page decoration technology principles and applications

1. Basic Concepts 1. Sitemesh is a page decoratio...