Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 146 Vote(s) - 3.34 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot truncate table because it is being referenced by a FOREIGN KEY constraint?

#21
If you're doing this at any sort of a frequency, heck even on a schedule, I would **absolutely, unequivocally never use a DML statement.** The cost of writing to the transaction log is just to high, and setting the entire database into `SIMPLE` recovery mode to truncate one table is ridiculous.

The best way, is unfortunately the hard or laborious way. That being:

- Drop constraints
- Truncate table
- Re-create constraints

My process for doing this involves the following steps:

1. In SSMS right-click on the table in question, and select *View Dependencies*
2. Take note of the tables referenced (if any)
3. Back in object explorer, expand the *Keys* node and take note of the foreign keys (if any)
4. Start scripting (drop / truncate / re-create)

Scripts of this nature *should* be done within a `begin tran` and `commit tran` block.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through