views:

420

answers:

1

Hey,

We have two tables in a SQL Server 2005 database, A and B.There is a service which truncates table A every day.

Recently, a foreign key constraint was added to table B, referencing table A. As a result, it isn't possible truncating table A anymore, even if table B is empty. Is there any workaround to get the same result as truncating table A?

I've already tried the approach below but the identity wasn't reset.

DBCC CHECKIDENT (TABLENAME, RESEED, 0)

PS. before anyone points this as a duplicate, the different thing here is that I'm not allowed to drop constraints, nor creating any.

A: 

If you can't drop the constraint, you can't use TRUNCATE TABLE, so you have to use DELETE.

DELETE TABLEA
DBCC CHECKIDENT (TABLENAME, RESEED, 0)

Note: Disabling the FK will not work either

gbn
I guess the problem was doing DELETE FROM TABLEA instead of DELETE TABLEA. Lame error, thanks for your help.
born to hula
@born to hula: these are the same: FROM is optional....
gbn
I don't know what I was doing wrong, then. Anyways, it works now.
born to hula