Truncate by ignoring the foreing key

Asked

Viewed 262 times

0

Cannot truncate table 'ARITHMETIC.glo.tbEndereco' because it is being referenced by a FOREIGN KEY Constraint.

Truncate has already been executed in the agency table that references the address that is, there are only addresses in the table not referenced by any other table

I want to make truncate in both to restart the records and there are no inconsistencies (Agencies no addresses and no addresses without agencies)

  • Could post in the question the SQL you are running?

  • is a simple command Truncate tbEndereco

  • I resolved to delete all records from the table and changing the auto increment value to 1

  • Show, put as Question Answer the executed commands to solve your problem.

1 answer

1


The alternative I found was to delete all records from the table and restart auto_increment

delete from tbEndereco where id < maxID+1
DBCC CHECKIDENT (tbEndereco, RESEED, 0)

Note: delete only worked because no record was referenced by another table


.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.