Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-01-11 : 08:47:02
|
| Ray writes "How do I prevent a circular reference in an insert trigger? My table can be reduced to :ID - int identity primary keyName - varcharParentID - int foreign key to IDHow do I write an insert trigger to prevent the following situation:ID=3 has ParentID=2 andID=2 has ParentID=1 andID=1 has ParentID=3I can't figure out how to write the insert trigger." |
|
|
jhermiz
3564 Posts |
Posted - 2005-01-11 : 11:59:12
|
WHERE ID <> 3 AND ParentID <> 2 ... ? Keeping the web experience alive -- [url]http://www.web-impulse.com[/url] |
 |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2005-01-12 : 05:15:33
|
| think of it logically.....you should be inserting ID 1 first....what parent does it get?...that parent should exist at that stage...if it doesn't the insert fails.you do have issues if you are restructuring the hierarchy after it has been created....but that should be resolved by identifying if the new parent is any child of the existing structure.Search here for "Hierarchies" for some articles/discussion points on this topic. |
 |
|
|
|
|
|