Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Truncate Function In Sql in SQL

Truncate Function In Sql in SQL

The TRUNCATE statement in SQL is used to quickly delete all rows from a table, removing data without logging individual row deletions. It’s faster than using a DELETE without a WHERE clause but does not log each deleted row.


? Key Points about TRUNCATE

  • Removes all rows from a table.

  • Resets identity counters (like auto-increment columns) in many databases.

  • Cannot be used with a WHERE clause (all rows are removed).

  • Faster and uses fewer system resources than DELETE.

  • Often cannot be rolled back depending on the database and transaction settings.

  • Does not fire triggers in many systems.


Syntax

TRUNCATE TABLE table_name;

Example

TRUNCATE TABLE Employees;

This removes all data from the Employees table quickly.


Differences between TRUNCATE and DELETE

FeatureTRUNCATEDELETE
Deletes rowsAll rows, no filteringRows can be filtered with WHERE
LoggingMinimal logging (usually)Logs each deleted row
TriggersUsually does not fireTriggers fire
Transaction rollbackDepends on DB (often can't)Can be rolled back
Identity resetResets identity countersDoes not reset identity
SpeedFaster for large tablesSlower for large tables

If you want, I can help you with examples or details for specific SQL databases!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql