June 4, 2009 at 12:23 pm
I want to truncate data.
1. So i do ALTER TABLE table1 NOCHECK CONSTRAINT ALL
2. Then i do TRUNCATE TABLE table1
3. Then i get an error java.sql.SQLException: Cannot truncate table 'table1 ' because it is being referenced by a FOREIGN KEY constraint.
The table has cyclic reference.
i.e it has an primary key id which is an foreign key in the next row.
Any help is greatly appreciated.
June 4, 2009 at 12:30 pm
SQL Server will not allow you to use the TRUANCATE TABLE command on a table referenced by a foreign key. You have 2 options.
1. Drop foreign key, truncate table, re-create foreign key.
2. Leave foreign key alone, use DELETE instead.
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy