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?

    Requires Free Membership to View

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.

This was first published in January 2006

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: