0

Hi I have Amazon rds which i can connect to using the mysql prompt

I want to empty a table using the prompt command line

What's the best way to do the above? Thanks!

user3236765
  • 373
  • 1
  • 2
  • 13

3 Answers3

1

You can use the standard truncate command to empty the required tables. If you want to truncate multiple tables follow this question.

Community
  • 1
  • 1
chinoy
  • 172
  • 1
  • 13
  • Hi is delete better or truncate? Also what's the format of the command? An example would be appreciated – user3236765 Dec 25 '16 at 08:12
  • Command is `TRUNCATE TABLE your_table_name`. In terms of speed truncate is faster. Both delete and truncate has its own set of rules. Please see [here](http://stackoverflow.com/questions/139630/whats-the-difference-between-truncate-and-delete-in-sql) for a comprehensive comparison between both commands. – chinoy Dec 25 '16 at 11:25
0

Try

DELETE FROM `table_name`;

Notice the missing where clause, this will delete all rows.

akuhn
  • 27,477
  • 2
  • 76
  • 91
0

Data can't be deleted that's connected by a constraint.

What you need is code that first removes constraints, then deletes the data, and finally restores the constraints:

Moreover, use DELETE command as you can ROLLBCK the operation. While using truncate, operation cannot be rolled back and no triggers will be fired

Muhammad Muazzam
  • 2,810
  • 6
  • 33
  • 62