By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
I am inserting records into a sample table at the same time that I'm giving the TRUNCATE TABLE command in another session. I got the "resource busy" error, so I killed the session. But I got the same error. How can I truncate the table?
The TRUNCATE TABLE command is a Data Definition Language (DDL) command, where as the INSERT, UPDATE and DELETE statements are Data Manipulation Language (DML) commands. DML commands only need a lock on the affected row. DDL commands need a lock on the entire table. If a DML command is unable to obtain a lock due to another transaction, it will wait for that lock to be released. If a DDL command is unable to obtain a lock, that DDL command is not willing to wait for the lock to be released, therefore you get the dreaded "resource busy" error message. In your case, you have three options. One, wait for the transactions holding the lock to finish and then issue your TRUNCATE TABLE command. Two, use the DELETE statement to remove all rows of data from the table. Three, kill the session(s) holding the lock and then issue the TRUNCATE command.