Este conteúdo foi traduzido por máquina para sua conveniência e a Huawei Cloud não pode garantir que o conteúdo foi traduzido com precisão. Para exibir o conteúdo original, use o link no canto superior direito para mudar para a página em inglês.
Computação
Elastic Cloud Server
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Redes
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Gerenciamento e governança
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
Cloud Operations Center
Resource Governance Center
Migração
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Análises
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
IoT
IoT Device Access
Outros
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Segurança e conformidade
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Serviços de mídia
Media Processing Center
Video On Demand
Live
SparkRTC
Armazenamento
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Cloud Server Backup Service
Storage Disaster Recovery Service
Scalable File Service
Volume Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Bancos de dados
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Aplicações de negócios
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Data Lake Factory
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Distribuição de conteúdo e computação de borda
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Soluções
SAP Cloud
High Performance Computing
Serviços para desenvolvedore
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
Cloud Application Engine
MacroVerse aPaaS
KooPhone
KooDrive
Nesta página
Central de ajuda/ GaussDB(DWS)/ Perguntas frequentes/ Uso do banco de dados/ Como excluir dados da tabela de forma eficiente?

Como excluir dados da tabela de forma eficiente?

Atualizado em 2025-01-23 GMT+08:00

Sim. TRUNCATE é mais eficiente que DELETE para excluir dados em massa.

Para obter detalhes, consulte TRUNCATE.

Função

TRUNCATE remove rapidamente todas as linhas de uma tabela de banco de dados.

Tem o mesmo efeito que DELETE incondicional, mas TRUNCATE é mais rápido, especialmente para tabelas grandes, porque não verifica tabelas.

Funções

  • TRUNCATE TABLE funciona como uma instrução DELETE sem cláusula de WHERE, ou seja, esvaziando uma tabela.
  • TRUNCATE TABLE usa menos recursos do sistema e do log de transações.
    • DELETE exclui uma linha a cada vez e registra cada exclusão no log de transações.
    • TRUNCATE TABLE exclui todas as linhas em uma tabela liberando a página de dados e registra apenas cada liberação da página de dados no log de transações.
  • TRUNCATE, DELETE e DROP são diferentes em que:
    • TRUNCATE TABLE exclui conteúdo, libera espaço, mas não exclui definições.
    • DELETE TABLE exclui conteúdo, mas não exclui definições ou libera espaço.
    • DROP TABLE exclui conteúdo e definições e libera espaço.

Exemplos

  • Crie uma tabela.
    1
    CREATE TABLE tpcds.reason_t1 AS TABLE tpcds.reason;
    

    Trunque a tabela.

    1
    TRUNCATE TABLE tpcds.reason_t1;
    

    Exclua a tabela.

    1
    DROP TABLE tpcds.reason_t1;
    
  • Crie uma tabela particionada.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    CREATE TABLE tpcds.reason_p
    (
      r_reason_sk integer,
      r_reason_id character(16),
      r_reason_desc character(100)
    )PARTITION BY RANGE (r_reason_sk)
    (
      partition p_05_before values less than (05),
      partition p_15 values less than (15),
      partition p_25 values less than (25),
      partition p_35 values less than (35),
      partition p_45_after values less than (MAXVALUE)
    );
    

    Insira dados.

    1
    INSERT INTO tpcds.reason_p SELECT * FROM tpcds.reason;
    

    Trunque a partição p_05_before.

    1
    ALTER TABLE tpcds.reason_p TRUNCATE PARTITION p_05_before;
    

    Trunque a partição p_15.

    1
    ALTER TABLE tpcds.reason_p TRUNCATE PARTITION for (13);
    

    Trunque a tabela particionada.

    1
    TRUNCATE TABLE tpcds.reason_p;
    

    Exclua a tabela.

    1
    DROP TABLE tpcds.reason_p;
    

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Conteúdo selecionado

Envie o conteúdo selecionado com o feedback