Reputation: 1391
Hi I am newby in Programming and Database work. I have question with Foreign key related.
I have two tables in sql server 2008. CallDetails,PageDetails.
For Example PageDetails Table.
PageId PageLoadTime PageUnloadTime
1 12:00PM 1:00PM
2 1:00PM 2:00PM
3 2:00PM 3:00PM
CallDetails Table
CallId CallStartTime CallEndTime
1 12:05PM 12:10PM
2 12:15PM 12:25PM
3 02:35PM 02:40PM
Now I want one more Cloumn as PageId in CallDetaiuls Table where CallId time should be between PageDetails time duration. Like, CallId 1 has PageId 1 ,CallId 2 has PageId 1,CallId3 has PageId 3.
I know Ican do this with giving foreign key to CallDetails Table But How can I give condition as above for assigning Foreign Key????
Upvotes: 0
Views: 161
Reputation: 1157
Foreign key only enforce that value in column PageId in CallDetails must occur in PageDetails table. For all other logic you can use for example:
*CHECK CONSTRAINTS(Not useful in your case) http://msdn.microsoft.com/en-us/library/ms188258.aspx
*DML TRIGGERS (for more complicated logic, comparing with data from another table etc.) http://msdn.microsoft.com/en-us/library/ms189799.aspx *Your own logic in application.
In this case I would use trigger. And also if you have one, another logic on the application side.
Upvotes: 1