Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can delete table data without deleting columnnames

Tags:

mysql

How can I delete table data, but not delete the 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 have to delete all content of table but the table column names should not be deleted.

DELETE FROM table_name WHERE [condition];
+----+----------+-----+-----------+----------+
| ID | NAME     | AGE | ADDRESS   | SALARY   |
+----+----------+-----+-----------+----------+
like image 593
R.sandeep Avatar asked Nov 17 '14 06:11

R.sandeep


People also ask

How can I delete data from a table without deleting a table in SQL?

The SQL TRUNCATE TABLE command is used to delete complete data from an existing table. You can also use DROP TABLE command to delete complete table but it would remove complete table structure form the database and you would need to re-create this table once again if you wish you store some data.

Can you delete all rows in a table without deleting the table?

Tip: You can delete the contents of a row or column without deleting the table structure. To do this, select the row or column and then press the Delete key.

How do you clear data from a table?

DELETE Syntax DELETE FROM table_name WHERE condition; Note: Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement.

What command is used to delete the data from the table without deleting the table structure?

TRUNCATE Command is a Data Definition Language operation. It is used to remove all the records from a table. It deletes all the records from an existing table but not the table itself.


1 Answers

Just use

DELETE FROM table_name;

or

DELETE * FROM table_name;

If you still want to add condition, you can use following:

DELETE FROM table_name WHERE 1=1;
like image 190
Sri Tirupathi Raju Avatar answered Oct 31 '22 15:10

Sri Tirupathi Raju