Thursday, October 4, 2012

Where are my documents stored?

NOTE: This post regards to SharePoint 2007 and SharePoint 2010 and SharePoint 2013, but there are some novelties in 2013 version, please refer to this post. Except different table name (AllDocStreams is called DocStreams in SP 2013), everything else is applicable to all SharePoint versions.


Have you ever wondered where does Sharepoint store all your documents you upload to document libraries?

No? Well, I'll tell you anyway.

Sharepoint stores all documents to a single SQL Server database, usually it is called WSS_Content, or, WSS_Content_someGuid if you have many Web Applications in your SP Farm. Yes, they are all stored to database, which is bad news for your machines performace.

Why is that bad?

Well, because documents (pdf, doc, xls, ...) are what we call BLOBs (Binary Large Object) and databases are not very good in handling BLOBs. Large amount of documents in Sharepoint is going to decrease performance of your server.

What can you do about that?

You can send all your BLOBs to a file system using EBS or RBS, but we'll talk about that some other time.

Today, let's just see where are our documents located.

Open SQL Management Studio and connect to Microsoft##SSEE database.

Expand Database in Object explorer on left side of the screen.
Expand WSS_Content database. This is what you get:


Now, you can see two tables where all your document data is stored; dbo.AllDocs and dbo.AllDocStreams.

Let's say that you have document in one of your libraries named "Report.xls". You can find it in dbo.AllDoc table:




In that table you can find all sort of data about your document, but document data is not there, it is in another table. Here you just need to copy Id of document so you can search document data in another table, dbo.AllDocStreams, like this:




And here, in column "Content" is your documents data.
That's it!

14 comments:

  1. Thanks mario. i was searching for this little stuff and you nicely written blog :)

    ReplyDelete
    Replies
    1. I am glad that you find it useful. I will update the information about SharePoint 2013 because the way the data is stored is somehow different from 2010 version.

      Delete
  2. Thanks Mario, I could find the file I am looking for, but seems that I can get only the Original file not the latest version of it... any ideas?

    ReplyDelete
    Replies
    1. In table AllDoc there is only one row which contains data about the Original file. All other versions are stored in table AllDocStreams. If you have 3 versions, then you will have 3 rows in AllDocStreams with the same ID, but with different InternalVersion and Content

      Delete
    2. I had an error in my script... I recovered the file version I was looking for.
      Thank you again

      Delete
    3. how i can export the excel file ? or the doc ?

      Delete
    4. I am not sure that I understand you. You want to export doc from SQL Server table? Isn't it easier to export files directly from SharePoint than from SQL Server?

      Delete
    5. I think , he meant to restore file directly from sql database if you for example have copy only database but not site with needed file .Telling the true I have the same situation :-).

      Delete
    6. Ok, the file is saved in "Content" column as I mentioned in the post. If you want to extract these bytes and save them as a file on your file system, then check out this link:
      http://stackoverflow.com/questions/10325338/fastest-way-to-export-blobs-from-table-into-individual-files

      And, I must mention that Microsoft forbade accessing the data in the database, but I assume that you already know that.

      Delete
  3. Thank you a lot. I'm confusing about performance of deleting large documents library and now you save my day. I'll delete directly from Database server (2 table AllDocs and DocStreams)

    ReplyDelete
  4. Thank you for your post Mario Zagreb :-)

    ReplyDelete
  5. Is there a simple way to count the total number of documents in a content database? E.g. can you look in SQL and check the total row count?

    ReplyDelete
    Replies
    1. Bill, yes you can do that, check out this post and modify the SQL command to do the count of all files
      http://sharepoint1on1.blogspot.hr/2013/07/sharepoint-list-size.html

      Delete