Create list relationships by using unique and lookup columns - SharePoint Foundation...

Page 1 of 6

Create list relationships by using unique and lookup columns
You can create relationships between lists by using a combination of unique columns, lookup columns, and relationship enforcement (cascade and restrict delete), all of which enhance your ability to create more sophisticated business solutions and help preserve the integrity of your data.

In this article
Overview of list relationships Creating unique columns Creating lookup columns A lookup column with an enforced relationship A lookup column with an unenforced relationship Viewing and editing items in list relationships Deleting items and lists in a list relationship Managing list relationships when lists have many items How to: Create or modify a unique column How to: Create a lookup column How to: Create relationships in the display and edit forms

Overview of list relationships
The following sections provides important background information about creating relationships between source and target lists, creating unique and lookup columns, enforcing list relationship behavior, adding primary and secondary lookup columns, viewing, editing, and deleting items within list relationships, managing list relationships when lists have many items, and the additional benefits of using an editing program such as Microsoft SharePoint Designer 2013.
Using unique and lookup columns to process gift orders.

 The Items list is the source list and the Orders list is the target list.  Each list has unique columns to ensure that the correct data is matched.  The primary lookup column in the source list "looks up" the Order ID column in the target list based on a matching value.  A secondary lookup column in the source list automatically inserts the Orders Description column from the target list.

Creating unique columns
When you create a column, you can specify that the column must contain unique values. This means that the list cannot have any duplicate values in that column. You cannot add a list item that contains a duplicate value, modify an existing list item that would result in creating a duplicate value, or restore an item from the Recycle Bin if it would result in a duplicate value. Furthermore, if you create a lookup column in a source list, and you define that column to be unique, the column in the target list must not contain duplicate values.
 NOTE     Uniqueness is not case-sensitive, so for example, ORD-231 and ord-231 are considered duplicate values.

A unique column must also have an index. When you create a unique column, you may be prompted to create the index and it is automatically created when you click OK. Once a unique column has an index, you cannot remove the index from that column, unless you first redefine the column to allow duplicate values. The following table summarizes what column types can and cannot be used to create unique columns. SUPPORTED COLUMN TYPES Single line of text UNSUPPORTED COLUMN TYPES Multiple lines of text

 

http://office.microsoft.com/en-us/sharepoint-foundation-help/create-list-relationships-b... 3/27/2014

http://office. For example. you want to ensure that the related item in the target list is preserved. as long as those additional columns have a supported data type described below. if you delete an order in a target list. a customer might still have that order pending. if someone tries to delete an order item from a target list. you create a lookup column that retrieves (or "looks up") one or more values from a target list if those values match the value in the lookup column in the source list.microsoft. you can continue to add additional columns (secondary columns) from the target list to the source list.  A restrict delete operation prevents deleting items in the target list if related source list items exist.  A cascade delete operation ensures all related items are deleted in one database transaction. You don't want the customer’s order to be accidentally deleted because that would affect your ability to complete the order. the related item or items in the source list are also deleted. Page 2 of 6 Choice (single value) Number Currency Date and Time Lookup (single value) Person or Group (single value) Choice (multi-valued) Calculated Hyperlink or Picture Custom Columns Lookup (multi-valued) Person or Group (multi-valued) Yes/No Creating lookup columns To create a relationship between two lists. You don't want to have order items without a corresponding order. Restrict Delete    When you try to delete an item in the target list... In this case. Once you create this lookup column (the primary column). In this case.Create list relationships by using unique and lookup columns . in the source list. The following table summarizes what column types can and cannot be used to create lookup columns. a lookup column with an enforced relationship and a lookup column with an unenforced relationship. and it has one or more related items in the source list. and you want to prevent that delete operation from occurring until the order has been processed. you are prevented from deleting the item in the target list.SharePoint Foundation. you can lookup single values and maintain the integrity of your data in the target list in one of two ways: Cascade Delete    When an item in the target list is deleted..com/en-us/sharepoint-foundation-help/create-list-relationships-b.. For example. A lookup column with an enforced relationship In a lookup column with an enforced relationship (also called referential integrity). because that would create "orphan" order items that might cause confusion later on. SUPPORTED COLUMN TYPES Single line of text Multiple lines of text Choice Number Date and Time Yes/No UNSUPPORTED COLUMN TYPES Currency Lookup Person or Group Calculated Hyperlink or Picture Custom Columns There are two types of lookup columns that you can create. you want to make sure that all related items are deleted as part of one database transaction. 3/27/2014 . you can ensure that the corresponding order items in the source list is also deleted.

The primary column name is a name you provide when you create the lookup column. by. as long as you have delete permission on the list. you might be prompted to create the index. filtering.microsoft. http://office. and sorting them.SharePoint Foundation.. If you create a lookup column with multiple values. Viewing and editing items in list relationships One of the beneficial effects of creating list relationships is that you can display and edit columns from two or more lists. changes the names of all secondary columns. there are no additional delete restrictions or delete operations that occur in the target list. when you delete an item in the source list..com/en-us/sharepoint-foundation-help/create-list-relationships-b. Once a lookup column that enforces a relationship has an index. By default. adding. removing.  NOTE     You must have Manage Lists permission on a list to create or modify an enforced relationship. Delete a source or target list item with an unenforced relationship    When you try to delete a source or target list item that does not have an enforced relationship. but you can also specify that additional.. from the source list. 3/27/2014 . Each secondary column value from the target list displays as text in the source list column. you may be blocked from deleting items even when you have delete permission. A lookup column that enforces a relationship must also have an index. You can manipulate these primary and secondary columns in list view in much the same way as the columns from the source list.  A secondary lookup column with multiple values.Create list relationships by using unique and lookup columns . • The related item in the target or source list is not deleted. The primary column value is a link that you can click to the display all the column values of that item in the target list. on one page. each secondary column name follows a standard naming convention of <primary column name in source list>: <column name in target list>. unless you first remove the enforced relationship. Also. then the following occurs: • You can remove the item from the source or target list. The following sections describe what happens in more detail. To maintain the integrity of the data. especially if the lists have an enforced relationship of restrict delete or cascade delete.. whether primary or secondary. you can modify the default secondary column names and descriptions to make the names more meaningful to you. therefore. display their multiple corresponding values delimited by semicolons. you cannot remove the index from that column. When you create a lookup column in a source list. However. Changing the name of the primary column. each column from the target list. which can take time to complete. the primary column displays values from the target list column. Deleting these items also requires the backend database to temporarily lock the data when performing the delete transaction.  A primary lookup column with multiple values.  The column name has been changed from the default name of GetID: Title to Instruments. and it is automatically created when you click OK. Deleting items and lists in a list relationship If you want to delete items or lists in a list relationship. A lookup column with an unenforced relationship In a lookup column with an unenforced relationship. then you need to be aware of the consequences of doing this operation on the source and target lists and any related columns. for example. you can lookup single or multiple values in the target list. When you create a lookup column that enforces a relationship. secondary columns from the target list also display alongside the primary column and the other source list columns. enforcing a list relationship behavior helps keep your data valid and helps prevent inconsistencies that might cause problems down the road. Page 3 of 6 In short.

or else the items cannot be restored. then all deleted items are stored in the recycle bin. then the following occurs: • You can delete the item in the target list and all related items in the source list. If the items were deleted in one database transaction as part of a cascade delete operation.. • You have exceeded the List View Lookup Threshold. and lists with enforced relationships. then you can delete either the source list or the target list. How to: Create or modify a unique column  WARNING     You cannot create a unique column in a list with item-level permissions defined. • When you try to delete an item in the target list. which by default is eight lookup columns.SharePoint Foundation. Delete a source list item with an enforced relationship of cascade delete    When you try to delete an item in the source list with an enforced relationship of cascade delete. all items in the relationship are displayed. you cannot create a unique column or modify a column to be unique in a list that contains items with unique permissions or one that has content approval enabled. • You cannot delete lists participating in an enforced relationship. a restrict delete operation will prevent you from deleting the item in the target list if it has one or more related items in the source list. • If you turn on Cascade Delete or Restrict Delete for a lookup field in a list that has more items than the List View Threshold. which means that the entire delete operation must complete to ensure that neither list is left in an invalid state. unique columns. then the following occurs: • You can then delete the item in the source list. • You cannot delete the source or target list. you can reach a resource threshold or limit and may be blocked under the following circumstances: • If you make a column unique in an existing list that has more items than the List View Threshold (but note that adding one item to a list that makes the list greater than the List View Threshold is an operation that is not usually blocked). Restoring from the Recycle Bin    If the Recycle Bin is enabled on your site. • The related item in the target list is not deleted. However. and you can restore them if you need to. even if you have delete permission on this item.Create list relationships by using unique and lookup columns .microsoft. Page 4 of 6 Delete a source list item with an enforced relationship of restrict delete    When you try to delete an item in the source list with an enforced relationship of restrict delete. Navigate to the site containing the list.. both items are still deleted. and those lists are displayed in the warning message. 3/27/2014 .. you cannot break inheritance of permissions from a list to a list item if the list contains a unique column. if that library contains a unique column. • The related item in the target list is not deleted Delete a target list item with an enforced relationship of restrict delete    When you try to delete an item in the target list with an enforced relationship of restrict delete. • The number of items in a delete operation exceeds 1. To summarize: • When an item in the target list is deleted. Delete a target list item with an enforced relationship of cascade delete    When you try to delete an item in the target list with an enforced relationship of cascade delete.000. Delete a source or target list with an enforced relationship of cascade or restrict delete    When you try to delete a source or target list with an enforced relationship of cascade or restrict delete. Find more information about thresholds and limits and managing lists and libraries with many items in the See Also section. Delete a source or target list with an unenforced relationship    When you try to delete a source and target list with an unenforced relationship. the following occurs: • You receive a warning that the source or target list has one or more relationships with other lists. • You cannot delete the target list item. the original target and source lists must still exist. 1. http://office. if the item in the source list is a checked out file.com/en-us/sharepoint-foundation-help/create-list-relationships-b. and you can restore them as well. then the following occurs: • You can remove the item from the source list. then the following occurs: • You receive an error message that the column is used to enforce the restrict delete operation. just like any other list. a cascade delete operation also deletes all related items in the source list. Managing list relationships when lists have many items When you create list relationships by using lookup columns. • The delete operation occurs as a database transaction. and you cannot copy a file to a library by using the Open with Explorer command..  NOTE     In the case of a Document Library.

and 6. remove the index. How to: Create relationships in the display and edit forms Once you create a lookup column. change the column to the other supported data type. type a name for the column. . and then change the column from allowing duplicate values to a unique column. and 10. click Lookup. How to: Create a lookup column 1. under Enforce unique values click Yes. In the Main Web Part Zone. In the Additional Column Settings section. select a target list. and then make the column unique. Click the name of the list on the Quick Launch. 8. click View All Site Content. you may be prevented from doing this operation if the existing column contains duplicate values. 6. 2. • If you want to change the data type of the unique column. select Add to default view. or on the Settings menu then under the list section. for each secondary column you want to add. and then remove the index. you can modify the display and edit forms of the target list so that related data from the source list is displayed. you must do the following: change the column to allow duplicate values. click the check box next to the column name.. Under The type of information in this column is. click the name of the list. If you want to remove the index. type a name for the column. 7. In the Columns Name box. Click Insert > Related List.  NOTES  • You cannot remove the index of a unique column. you can edit the display or edit page for the Orders list to add the related Items list and automatically connect the two corresponding List View Web Parts together by the passing the Lookup column value. 3/27/2014 . Later on if you want to add or remove secondary columns. select a primary column. Items). To create an enforced relationship. In the Get information from box. 4. 9. 11. modify the lookup column and make the selections you want. For example. click View All Site Content. click the name of the list. Click List > Create Column. Under Add a column to show each of these additional fields. click Add Web Part. 3. you must remove all the duplicate values first.  NOTE     Only lists for which you have View Items permission are displayed. • If you try to change an existing column from duplicate values to unique values.. Navigate to the site containing the list. Under The type of information in this column is.. and then select the related list (for example. 1.com/en-us/sharepoint-foundation-help/create-list-relationships-b. 5. In the Columns Name box. In the target list (for example.  NOTE     You cannot index a secondary column nor can you make a secondary column unique. 5. the Enforce unique values is not displayed. 3.SharePoint Foundation. Click List > Create Column. 2. 3. Click the name of the list on the Quick Launch. you must change the column from a unique column to one that allows duplicate values first. Click OK. 12. If you select a data type that is not supported. or of you are creating a lookup column that allows multiple values. Page 5 of 6 2. 4. In the In this column box.Create list relationships by using unique and lookup columns . If you want the lookup columns to display in the default view. Only columns with supported data types are listed. In this case.. or on the Settings menu then under the list section. Orders) click List > Modify Form Web Parts > Default Display Form or Default Edit Form. click one of the following: • Single line of text • Multiple lines of text • Choice • Number • Currency • Date and Time • Yes/No • Lookup (single value) • Person or Group (single value) . http://office. select Enforce relationship behavior and then click Restrict Delete or Cascade Delete.microsoft.

After you save the page. Page 6 of 6 The two lists are automatically connected. when you display or edit an item from the Orders list.. the related items in the Items list also display. http://office. Site Directory Contact Us Submit Feedback Legal Trademarks Privacy and Cookies Accessibility © 2014 Microsoft Corporation.com/en-us/sharepoint-foundation-help/create-list-relationships-b.. 3/27/2014 .microsoft...Create list relationships by using unique and lookup columns . All rights reserved.SharePoint Foundation.