Reputation: 671
How can I delete all the data in an SQL table, but not delete the columns? I want all the column names and attributes to still be there after the data is deleted.
Upvotes: 1
Views: 3882
Reputation: 11032
delete from tablename;
it can also work
truncate table tablename
I didn't read the question
EDIT I checked for
delete from tablename;
it is also working..am i right??downvoters can you please tell the reason
'truncate'..'truncate' is more efficient than 'delete'..
Upvotes: 0
Reputation: 23596
You could either use:
TRUNCATE TABLE `tableName`;
From the MySQL docs:
TRUNCATE TABLE empties a table completely. Logically, this is equivalent to a DELETE statement that deletes all rows, but there are practical differences under some circumstances.
You could also use DELETE FROM tableName
, but using TRUNCATE TABLE tableName
is better because:
Truncate operations drop and re-create the table, which is much faster than deleting rows one by one, particularly for large tables.
Upvotes: 3
Reputation: 77
Please use this syntax in your sql editor
Ex: truncate table tablename
table name: demo
truncate table demo
this will delete only data and not the columns
Upvotes: 3
Reputation: 4255
The syntax might vary slightly depending on your database, but you probably want something like:
TRUNCATE TABLE my_table_name;
Also, DELETE FROM my_table_name
will also work, but generally be much slower than TRUNCATE
.
Upvotes: 6
Reputation: 1950
Did you try the using TRUNCATE??
TRUNCATE TABLE YOUR_TABLE_NAME;
Upvotes: 3