maria-db
  1. maria-db-delete-truncate-table

Truncate Table - (MariaDB CRUD Operation)

In MariaDB, TRUNCATE TABLE is a CRUD (Create, Read, Update, Delete) operation that removes all rows from a table without logging individual row deletions, and resets any auto-incrementing columns to their starting value.

Syntax

The syntax for using TRUNCATE TABLE in MariaDB is as follows:

TRUNCATE TABLE table_name;

Here, table_name is the name of the table you want to truncate.

Example

Here is an example of using TRUNCATE TABLE in MariaDB to delete all rows from a table called employees:

TRUNCATE TABLE employees;

Output

Executing the SQL command will remove all rows from the employees table and reset any auto-incrementing columns to their starting value.

Explanation

In the above SQL code, we are using the TRUNCATE TABLE command to delete all rows from the employees table. This operation removes all rows from the table without logging individual row deletions and resets any auto-incrementing columns to their starting value.

Use

The TRUNCATE TABLE command is often used in situations where you want to remove all data from a table, such as when you want to start fresh with new data or when you no longer need the data in the table.

It is important to note that the TRUNCATE TABLE command is different from the DELETE command in that it does not log individual row deletions, which can make it faster and less resource-intensive.

Important Points

  • TRUNCATE TABLE is a MariaDB CRUD operation that removes all rows from a table without logging individual row deletions.
  • The syntax for using TRUNCATE TABLE is TRUNCATE TABLE table_name;.
  • TRUNCATE TABLE is often used when you want to remove all data from a table.
  • TRUNCATE TABLE is faster and less resource-intensive than the DELETE command.

Summary

In summary, TRUNCATE TABLE is a MariaDB CRUD operation that deletes all rows from a table without logging individual row deletions and resets any auto-incrementing columns to their starting value. It is often used when you want to remove all data from a table and is faster and less resource-intensive than the DELETE command.

Published on: