PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

SQL · Theory

TRUNCATE Table

← All stacks

Theory

17/439

TRUNCATE Table

TRUNCATE TABLE students; deletes every row fast and resets AUTO_INCREMENT. The table structure stays. It is DDL in MySQL — you usually cannot ROLLBACK a truncate like a DELETE in a transaction (engine/version details aside: treat TRUNCATE as ‘gone’).

DELETE FROM students; also removes all rows but logs each row, fires DELETE triggers, and can be rolled back in a transaction. Use DELETE when you need WHERE, triggers, or rollback. Use TRUNCATE when you want an empty table quickly in practice.

Trap: TRUNCATE on a table that other tables reference with FOREIGN KEY — InnoDB may refuse. Trap: thinking TRUNCATE is the same as DROP TABLE (DROP removes the table itself).

On the example next to this theory: TRUNCATE Table — dELETE removes matching rows. TRUNCATE clears a whole table faster (MySQL).

Exam tip

TRUNCATE = empty table, keep columns. DELETE = can WHERE and rollback.

TRUNCATE Table — sample query

CREATE TABLE tags (id INTEGER PRIMARY KEY, label TEXT);
INSERT INTO tags VALUES (1, 'old'), (2, 'keep');
DELETE FROM tags WHERE label = 'old';
SELECT * FROM tags;

TRUNCATE Table — dELETE removes matching rows. TRUNCATE clears a whole table faster (MySQL).

Short notes

  • DefTRUNCATE removes all rows, keeps the table, resets AUTO_INCREMENT.
  • RuleDELETE if you need WHERE / rollback / triggers.
  • TrapTRUNCATE ≠ DROP TABLE.

Questions

1

TRUNCATE vs DELETE all rows?

2

TRUNCATE vs DROP?

17 / 439

P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.