How many tables? Do the tables have an ID column? As other posters have said you can simply delete where ID > 20 so
DELETE from TABLE where ID > 20;
I have several tables containing over 20k rows. Is there a quick way to delete all but the first 20 rows in each of the tables?
I suppose it's worth asking why you want to do this?
There's probably a better way to solve the underlying problem that you're trying to solve.

I've sometimes thought it would be useful to create a storage engine that returns result sets using a randomly-chosen way of ordering: each time you run a query without an ORDER BY clause it just picks one of order-of-insertion, reverse-order-of-insertion, every-other-record-by-order-of-insertion-followed-by-the-rest-in-reverse-order-of-insertion-permuted-according-to-the-fibonacci-series... and of course randomly-ordered, along with lots of others. It would be a useful training tool, reminding people that if they want things ordered a particular way, they need to say so. I've also thought of doing the same thing with the "for-each" construct in XSLT - too many people think it operates like a loop, but of course there's no such thing as a loop (which implies a temporal sequence of events) in declarative languages like SQL or XSLT. It all happens outside time![]()
I suppose it's worth asking why you want to do this?
There's probably a better way to solve the underlying problem that you're trying to solve.
I know there's commercial Data Masking tools you can get to anonymize customer data (e.g. for dev/test databases) - Informatica have one - but I can't instantly find any free ones that seem worth looking at. Good project for someone to code an open source one.No real problem to solve just setting up a duplicate system for a new dev to work on but wanted to strip out all the real customer data.
Thanks to the excellent pointers I got the job done with minimum of fuss and nothing broken.
I know there's commercial Data Masking tools you can get to anonymize customer data (e.g. for dev/test databases) - Informatica have one - but I can't instantly find any free ones that seem worth looking at. Good project for someone to code an open source one.