In this article, I am going to explain how to implement referential integrity between lists in SharePoint Foundation 2010.
I have created two lists "Course (Parent list)" and "Student (Child list)". The parent list (Course) contains four columns i.e. Title, Course_ID, Course_Name and Duration and child list (Student) contains four columns i.e. Title, Student_ID, Student_Name, and Course. In the "ChildList (Student)" I am creating a lookup column (Course) which will take values from the "ParentList (Course) column (Course_ID)". Whenever you create a lookup column you can see "Relationship" where you can maintain referential integrity enforcing the relationships defined by lookup columns. Just like foreign key constraints in a relational database, in SharePoint 2010 you can configure restrict delete and cascade delete rules on lookup column relationships.
Cascade Delete:When an item in the parent list is deleted, the cascade delete will delete all related items from the child lists.
Restrict Delete:It will prevent the deletion of an item in the parent list if it has one or more related items in the child list. When you try to delete an item in the parent list you will get the error message.
Here I am going to implement both Cascade and Restrict deletion:
1) Restrict Deletion:
· Create a Course List (Parent List):
Site Actionsà More Options…à List à Custom List.
Add columns and courses in the Course list as shown in the list below:
· Create a Student List (Child List):
Site Actionsà More Options…à List à Custom List.
Note: While creating a Course column in the Student list chooses the following option as shown in the below figure:
Now when you attempt to delete the information present in the child list (Student) from the parent list (Course) it will give an error as shown in the below dialog box:
1) Cascade Deletion:
In order to implement cascade deletion change the Course column relationship behaviors of the Student table into Cascade delete.
Student Listà List Tools à List ribbon à List Settings.
Change the column (Course) behavior to Cascade delete:
Now when you attempt to delete the information from the parent list (Course) it will also remove the matching information from the child list (Student).
Here I am going to delete the course id from the Course list that is also present in the Student list:
It will remove the matching course id present in the Student list:
Thanks for reading this article. I think this will help you a lot.
Leave Comment