After my first small paternity
leave from about two weeks I got a direct tweed asking for a sql
script which is cleaning all unnecessary versions from all nodes at
once. Unlike to the SQL Script posted
before which deletes all versions from a given nodeId (usefull
if you have a massive growing database with thousand of versions
for one node) this script will delete all unnecessary versions from
all nodes at once. As usual this is a works on my machine post.
Please make a backup from your database and report
misbehaviour.
At first the script will create a temporary table and inserts all nodeId's from nodes which are documents (remember, not only documents have versions, also members and medias can have versions) and which are published and not in the recycle bin.
-- Create a temporary table for all documents which are published and not in the recycle bin
CREATE TABLE #Nodes (id int)
-- Delete all rows if the table exists before
TRUNCATE TABLE #Nodes
-- Insert all nodeIds from all documents which are published and not in the recycle bin
INSERT INTO #Nodes
SELECT N.id
FROM umbracoNode N
INNER JOIN cmsDocument D ON N.ID = D.NodeId
WHERE nodeObjectType = 'C66BA18E-EAF3-4CFF-8A22-41B16D66A972'
AND [path] NOT LIKE '%-20%'
AND D.Published = 1
After that it creates another temporary table and inserts all versions from the nodeIds in the first temporary table which not are published an which not are the newest ones.
-- Create a temporary table for all versionId's to delete
CREATE TABLE #Versions (id UniqueIdentifier)
-- Delete all rows if it exists before
TRUNCATE TABLE #Versions
-- Insert all versionId's from all nodeIds in the #Nodes table
-- and where published is set to false and newest is set to false
INSERT INTO #Versions
SELECT versionId
FROM cmsDocument
WHERE nodeId IN (SELECT id FROM #Nodes)
AND published = 0 AND newest = 0
Now it will delete all rows from the cmsPropertyData, cmsContentVersion and cmsDocument where the versionId's are in the second temporary table.
-- DELETE all versions from cmsPropertyData, cmsContentVersion, cmsDocument -- from the nodes which are published and which are not in the recycle bin -- and which are not published and which are not the newest DELETE FROM cmsPropertyData WHERE VersionId IN (SELECT id FROM #Versions) DELETE FROM cmsContentVersion WHERE VersionId IN (SELECT id FROM #Versions) DELETE FROM cmsDocument WHERE VersionId IN (SELECT id FROM #Versions)
Unlike the script in the post Cleaning versions in the umbraco db for given nodes via SQL this script doesn't delete the indexes. If the script runs to long you are free to add these step to this script. On the other hand this script can be used as a regularly cleanup.
Download the complete script here and give me your feedback.
09.07.10 20:02: Aaaaadler ;-)
09.07.10 20:01: Einmal Bier holen = Tor verpasst => Der Weg in den Keller ist eindeutig zu lang...
09.04.10 06:04: @Shazwazza Done ;-) #ucomponents #Umbraco
09.03.10 20:43: @netaddicts LOL
09.03.10 20:43: @asp_net wie war das bei der 2010 Roadshow, Zitat: 'google das mal mit Bing'
![]()
This blog is written by Thomas Höhler. Living next to Frankfurt, Germany,
I am trying to share my experiences about
Umbraco [the most flexible CMS I know],
my ClientTools for Umbraco,
and some other more or less usefull stuff