Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

triggerrs or foreign keys????pleaseeee

Status
Not open for further replies.

korel038

Technical User
Sep 28, 2003
6
GR
Hi there...a simple question for u guys that i am sure do know a lot more than me since i am just a beginner in sql server...(i have used 7 and 2000)but for a little while...

which is faster....?(and recommendable)
triggers or relationships(foreign keys)...and if possible why!
Thanks in advance!
john
 
Depends entirely on what you want to do?! If you want to simply set up relationships between tables using foreign keys then use foreign key constraints. All these do is check when you insert a value in the specified column that it exists in the referenced column. They also don't allow deletions from the referenced column if the value still exists in the specified column.

Triggers allow you to specify actions to take when rows are inserted, updated or deleted. You can check the values and take different actions depending on them, code complex logic etc. Be aware that triggers can affect performance of the table quite drastically if not designed and coded well, as all actions will only commit once the trigger has completed.

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top