Home » SQL

Using TRUNCATE TABLE in SQL

In this article, we are going to learn about TRUNCATE TABLE to delete complete data from an existing table in SQL.
Submitted by Manu Jemini, on March 06, 2018

There are times when you want to delete the whole records from the table but also to keep the table. Now, we cannot do this by dropping the table itself as we will lose the table itself.

To make this possible to actually keep the table we need truncate the table by a SQL query. This has a very simple syntax because all we need to do is to use the truncate keyword and give it a TableName.

TRUNCATE TABLE table_name;

This is enough to delete every record from the table. There are cases when you really do not have any way other than deleting every record one by one, which could be very hard. Hence, learning this query will help you a lot.

Dummy data:

TRUNCATE TABLE in SQL

Syntax:

TRUNCATE TABLE  table_name;

Example 1:

TRUNCATE TABLE 'includehelp'.'employee';
TRUNCATE TABLE in SQL Output 1

Example 2:

TRUNCATE TABLE 'includehelp'.'company';
TRUNCATE TABLE in SQL Output 2





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.