Search code examples
sqlsql-servertruncate

Truncating a MS SQL Server Express table with one record takes forever


I am setting up a kind of test database in Microsoft SQL Server Express 2017. I have one main table with 10 columns, which is linked to 6 others, ie its primary key is the foreign key of 6 other tables.

I have populated this main table with just one record.

I need to truncate it - ie delete all the rows but not the table. I tried both truncate table and delete from but both take forever: after 4 minutes the query was still executing! I understand there are keys to check etc, but it's only one record. All the other tables are empty. This doesn't seem right. Any ideas what could be wrong and what I can do to fix it?


Solution

  • In response to the comment

    It is probably uncommitted transactions, on your child tables.

    You would first be deleting all the child records prior to deleting the parent table record. Is the child tables all empty?.

    Do you have any uncommitted transactions in any of those tables? If you do then attempt to kill those sessions by engaging a dba.