Introduction

It is often a point of discussion when many users ask how SharePoint saves list data. One straight answer we can provide is "in a content DB". But, most developers do not know the internals, except we all know the basic point that we should not play with a content DB.

Knowing the internals will help us to understand performance and articulate better code while requesting data from the list.

Main Points Covered

The main points covered in this article are:

AllLists

An AllLists table in a content DB stores the information when a list is created. It might be very complex to describe every column, but if we get to know some important columns then we will certainly understand what is happening.

Columns

AllUserData

The AllUserData table in the content db is the single table to store items of any list. This table has 192 columns and all the list items including their history is saved in this table. Documents uploaded to an item or documents in the document library are also saved in this table.

The primary key (non clustered) of this table consists of 7 columns.

Columns

A custom list SalesInfo is created.

Its tp_ID value from the AllItems table is 1FB218D6-8C61-45A5-B30D-32EF4F8087AC

Schema of the custom list "SalesInfo"

"Title" field - single lie of text

"ProductType" field - Choice type (values Hardware,Software)

"ProductCompany" field - single line of text

"Comments" field - single line of text

I have created 2 values in the list. The following is the list image:

Image 2.jpg

Now we will check the AllUserData table.

Image 3.jpg


It has two rows inserted with tp_ListId which is 1FB218D6-8C61-45A5-B30D-32EF4F8087AC, the value from the AllItems table.

Now we will see the values in the same rows in various columns.

Image 4.jpg



The title value is saved in the "nvarchar1′ column.

The choice values are saved in the "navarchar3′ column.

Another sigle line of text (ProductCompany) value is saved in "nvarchar4′ column.

The Comments field value is saved in the "nvarchar5′ column for one item and for another item value is null.

Every time we create a column in a SharePoint list, internally it will check the available free columns in AllUserdDatatable and map to them. Once mapped, SharePoint will save information in that column. It is more complex to discuss what if all the columns are full and how SharePoint is handling this.

Check the tp_DeleteTransactionId, it is "0x"; that means that it is not deleted.

Now I have deleted an item, it looks like the following image:

Image 5.jpg


When any user restores from the recycle bin, its tp_DeleteTransactionId will be back to "0x".

Conclusion

We can also write your own SQL queries on this table to get specific list data, but remember any changes to the content DB are not supported by Microsoft. We have to respect the fact that we should not modify a content DB. When you write a CAML query on any list, internally it will execute a SQL query on this table with conditions.

If you have planned to write custom queries on this table, you should be well aware of the where conditions as there is no specific document explaining the internals of the content DB.

Hope you enjoyed the article to understand what is happening when a list and item are created, though the intention is not to modify the content DB.