How to delete table data without deleting column names

How to delete table data but not delete table column names?

         ID | NAME     | AGE | ADDRESS   | SALARY   |
        +----+----------+-----+-----------+----------+
        |  1 | Ramesh   |  32 | Ahmedabad |  2000.00 |
        |  2 | Khilan   |  25 | Delhi     |  1500.00 |
        |  3 | kaushik  |  23 | Kota      |  2000.00 |
        |  4 | Chaitali |  25 | Mumbai    |  6500.00 |
        |  5 | Hardik   |  27 | Bhopal    |  8500.00 |
        |  6 | Komal    |  22 | MP        |  4500.00 |
        |  7 | Muffy    |  24 | Indore    | 10000.00 |
        +----+----------+-----+-----------+----------

I need to delete the entire contents of the table, but the column names of the table should not be deleted.

 DELETE FROM table_name
    WHERE [condition];
        ID | NAME     | AGE | ADDRESS   | SALARY   |
+4
source share
4 answers

Just use

DELETE FROM table_name;

or

DELETE * FROM table_name;

if you want to add a condition

DELETE FROM table_name where 1 =1;
+3
source

This is equivalent to the DELETE statement:

TRUNCATE TABLE yourTableName;
+2
source

:
SQL - TRUNCATE TABLE http://goo.gl/YN7N9Y
SQL - http://goo.gl/viyYFU

SQL TRUNCATE TABLE .

You can also use the DROP TABLE command to delete the full table, but it will remove the full table structure from the database, and you will need to create this table again if you want to save some data.

Syntax:

The basic syntax is TRUNCATE TABLEas follows:

TRUNCATE TABLE  table_name;

Example: Consider a CUSTOMERS table with the following entries:

+----+----------+-----+-----------+----------+
| ID | NAME     | AGE | ADDRESS   | SALARY   |
+----+----------+-----+-----------+----------+
|  1 | Ramesh   |  32 | Ahmedabad |  2000.00 |
|  2 | Khilan   |  25 | Delhi     |  1500.00 |
|  3 | kaushik  |  23 | Kota      |  2000.00 |
|  4 | Chaitali |  25 | Mumbai    |  6500.00 |
|  5 | Hardik   |  27 | Bhopal    |  8500.00 |
|  6 | Komal    |  22 | MP        |  4500.00 |
|  7 | Muffy    |  24 | Indore    | 10000.00 |
+----+----------+-----+-----------+----------+

The following is an example of truncation:

SQL > TRUNCATE TABLE CUSTOMERS;

Now the CUSTOMERS table is truncated, and the following result will be output from the SELECT statement:

SQL> SELECT * FROM CUSTOMERS;
Empty set (0.00 sec)
0
source

All Articles