Problem solve Get help with specific problems with your technologies, process and projects.

Deleting 4000 rows from a table at once

I'll delete 4000 rows from my database. I've a unique number as a "where search" conditions, meaning that only rows that are matching with the numbers will be deleted. I have a file containing those 4000 unique numbers. Is there any way to delete the 4000 numbers all at once, instead of one by one manually?

You can delete all the rows in a table by simply leaving off the WHERE clause entirely. For example:

DELETE FROM mytable;  
This statement will delete all the rows in the mytable table.

If the table you are using to delete the 4000 rows from has other records in it that you do not want to delete, you can still do the deletes in a single statement in one of several ways. If the numbers you wish to delete are consecutive, such as 1-4000 or 200-4200 etc, then you can write your delete statement like this:

DELETE FROM mytable WHERE column_name BETWEEN 1 AND 4000;
If the numbers you wish to delete are not consecutive, you can list each number as follows:
DELETE FROM mytable WHERE column_name IN (1,2,4,50,66,22....and so on) ;

For More Information

  • What do you think about this answer? E-mail the editors at editor@searchDatabase.com with your feedback.
  • The Best Oracle Web Links: tips, tutorials, scripts, and more.
  • Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
  • Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
  • Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.

Dig Deeper on Oracle and SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.