Tuesday, October 16, 2012

Delete library and documents directly via SQL in SharePoint 2010

This is not a good idea, but sometimes you have no choice and you must delete a SharePoint library and the documents directly via a MSSQL query.

I did not find any documentation about it, but after some research in the SharePoint SQL tables, I tried this:

DO NOT FORGET TO BACKUP YOUR SHAREPOINT BEFORE !


Declare @ListId as VarChar(200)
Set @ListId = 'MyListId'                   /*** you have to give the List Id ***/


/********* FILES STREAM DELETE *****************/ 
delete from AllDocStreams where Id in (Select Id from AllDocs where listId = @ListId and Leafname <> 'Form')


/********* FILES & LIST INFO DELETE  *****************/ 
delete FROM AllDocs where listId = @ListId


/********* LIST INFO DELETE (Number of files in the library and next available ID) *****************/
delete FROM AllListsAux where listId = @ListId


/********* LIST INFO DELETE (extra info) *****************/
delete FROM AllListsPlus where listId = @ListId




This script is definitely incomplete, so any help is welcome!

No comments:

Post a Comment