tencent cloud

TDSQL Boundless

Release Notes
Product Introduction
Overview
Scenarios
Product Architecture
Instance Types
Compatibility Notes
Usage specification recommendations
Kernel Features
Kernel Overview
Kernel Version Release Notes
Functionality Features
Performance Features
Billing
Billing Overview
Purchase Method
Pricing Details
Renewal
Overdue Payments
Refund
Getting Started
Creating an Instance
Connect to Instances
User Guide
Data Migration
Data Subscription
Instance Management
Parameter Configuration
Account Management
Security Group
Backup and Restoration
Database Auditing
Tag Management
Use Cases
Technical Evolution and Usage Practices of Online DDL
Lock Mechanism Analysis and Troubleshooting Practices
Data Intelligent Scheduling and Related Practices for Performance Optimization
TDSQL Boundless Selection Guide and Practical Tutorial
Developer Guide
Developer Guide (MySQL Compatibility Mode)
Developer Guide (HBase Compatibility Mode)
Performance Tuning
Performance Tuning Overview
SQL Tuning
DDL Tuning
Performance White Paper
Performance Overview
TPC-C Test
Sysbench Test
API Documentation
History
Introduction
API Category
Making API Requests
Instance APIs
Security Group APIs
Task APIs
Backup APIs
Rollback APIs
Parameter APIs
Database APIs
Data Types
Error Codes
General Reference
System Architecture
SQL Reference
Database Parameter Description
TPC-H benchmark data model reference
Error Code Information
Security and Compliance
FAQs
Agreements
Service Level Agreement
Terms of Service
Privacy Policy
Data Processing And Security Agreement
Contact Us
Glossary

Data Deletion

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-03-26 14:37:49
Introduces how to delete data from a table, primarily covering the usage methods, differences, and considerations of two statements: DELETE and TRUNCATE TABLE.

DELETE statement

The DELETE statement is standard SQL syntax used to remove specified records from a table.

Syntax

DELETE FROM tbl_name [WHERE where_condition] [ORDER BY ...] [LIMIT row_count];

Parameter Description

WHERE where_condition: (Optional) Specifies the deletion condition, deleting only records that meet the condition.
ORDER BY: (Optional) Specifies the deletion order.
LIMIT row_count: (Optional) Limits the number of rows to delete in a single operation.

Use Case

1. Create a test table.
CREATE TABLE sbtest1 (id INT PRIMARY KEY, v1 INT, v2 INT, v3 INT);
2. Delete data that meets the condition.
DELETE FROM sbtest1 WHERE v1 = 100;
3. Delete the specified number of data.
DELETE FROM sbtest1 WHERE v2 < 1000 LIMIT 1000;
4. Delete the specified number of data in the specified order.
DELETE FROM sbtest1 ORDER BY id LIMIT 500;
5. Delete all data from the entire table.
DELETE FROM sbtest1;

TRUNCATE TABLE

TRUNCATE TABLE is used to quickly remove all data from a table.

Syntax

TRUNCATE TABLE tbl_name;

Use Case

1. Clear table data.
-- Create a test table.
CREATE TABLE sbtest1 (
id INT PRIMARY KEY,
v1 INT,
v2 INT,
v3 INT
);

-- Quickly clear all data in the table.
TRUNCATE TABLE sbtest1;
2. Clear a partition.
-- Create a RANGE partitioned table
CREATE TABLE sbtest2 (
id INT,
create_time DATE,
v1 INT,
PRIMARY KEY (id, create_time)
)
PARTITION BY RANGE (TO_DAYS(create_time)) (
PARTITION p202401 VALUES LESS THAN (TO_DAYS('2024-02-01')),
PARTITION p202402 VALUES LESS THAN (TO_DAYS('2024-03-01')),
PARTITION pmax VALUES LESS THAN MAXVALUE
);

-- Quickly clean up data for January 2024.
ALTER TABLE sbtest2
TRUNCATE PARTITION p202401;

Limitations

1. It is recommended to back up important data before deletion operations are performed.
2. It is recommended to verify large-scale deletion operations in a test environment before they are executed in a production environment.
3. Monitor the impact of deletion operations on system performance.
4. Properly configure the transaction timeout period to avoid long-running transactions blocking the system.


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백