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!
Thanks mario. i was searching for this little stuff and you nicely written blog :)
ReplyDeleteI 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.
DeleteThanks 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?
ReplyDeleteIn 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
DeleteI had an error in my script... I recovered the file version I was looking for.
DeleteThank you again
You are welcome.
Deletehow i can export the excel file ? or the doc ?
DeleteI 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?
DeleteI 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 :-).
DeleteOk, 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:
Deletehttp://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.
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)
ReplyDeleteThank you for your post Mario Zagreb :-)
ReplyDeleteIs 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?
ReplyDeleteBill, yes you can do that, check out this post and modify the SQL command to do the count of all files
Deletehttp://sharepoint1on1.blogspot.hr/2013/07/sharepoint-list-size.html
Hi Mario. Are able to assist or direct me? I would like to migrate data from sharepoint to another sql database as we will no longer using sharepoint. I have already identified tables AllUserData & AllUserDocs in Wss_content however still trying to understand how the AllUserdata is linked to AllUserDocs so that I can associate the user data with the documents.
ReplyDeleteHello Russell, sorry for my late response.
DeleteI would not recommend you to migrate your data directly from SQL Server database since the links between tables are difficult to find (as you noticed). I would suggest to to use SharePoint API and try to build application with Visual Studio using C# language and SharePoint API (SSOM or CSOM). With that, you can read list items or document and then store them in your database.
They’re really convincing and will definitely work. Still, the posts are too brief for newbies. May you please extend them a little from subsequent time?Also, I’ve shared your website in my social networks.
ReplyDeleteDocument Management Software
Electronic Document Management System
Cloud Document Management System
Document Management System
Electronic Document Management Software