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

Implementing user registration function with js

This article example shares the specific code of ...

Start nginxssl configuration based on docker

Prerequisites A cloud server (centOS of Alibaba C...

Linux disk sequential writing and random writing methods

1. Introduction ● Random writing will cause the h...

Mysql implementation of full-text search and keyword scoring method example

1. Introduction Today a colleague asked me how to...

MySQL uses custom sequences to implement row_number functions (detailed steps)

After reading some articles, I finally figured ou...

VMware Workstation is not compatible with Device/Credential Guard

When installing a virtual machine, a prompt appea...

Summary of MySQL composite indexes

Table of contents 1. Background 2. Understanding ...

What are your principles for designing indexes? How to avoid index failure?

Table of contents Primary key index Create indexe...

Use of Linux crontab command

1. Command Introduction The contab (cron table) c...

js to achieve the pop-up effect

This article example shares the specific code of ...

Solve the problem of black screen when starting VMware virtual machine

# Adjust VMware hard disk boot priority Step 1: E...

Detailed explanation of downloading, installing and using nginx server

download http://nginx.org/en/download.html Unzip ...

Understanding and using callback functions in JavaScript

Table of contents Overview What are callbacks or ...