List the differences between the following MySql commands.
- drop table tablename;
- truncate table tablename;
- delete from tablename where 1;
Also from your experiences please tell me typical usage scenario for each.
List the differences between the following MySql commands.
Also from your experiences please tell me typical usage scenario for each.
Drop is deleting the table. I would drop the table if I didn't need it anymoredelete to do a delete (of specific rows) with a query.I rarely "delete" anything from my databases. I generally put a flag column such as deleted as a boolean value. I check for that. If its true, I don't present that data.
drop table tablename;
truncate table tablename;
DELETE because it simply deletes all data. DELETE will scan the table to generate a count of rows that were affected.delete from tablename;
WHERE clause.DELETE FROM tablename WHERE username = 'joe'In addition to the answers above, on Oracle RDBMS, "delete" is a transaction that can be rolled back if you didn't commit. "Truncate" cannot.