Wednesday, May 1, 2019

You can skip the WITH(NOLOCK) when querying Sitecore's dbo.Fields sql view

Don't worry about adding a NOLOCK hint to your SELECT queries against the Fields view in Sitecore.  They already include that hint on all of the tables.


SELECT id, 
       itemid, 
       '' AS Language, 
       fieldid, 
       value, 
       created, 
       updated 
FROM   dbo.sharedfields WITH (nolock) 
UNION ALL 
SELECT id, 
       itemid, 
       language, 
       fieldid, 
       value, 
       created, 
       updated 
FROM   dbo.unversionedfields WITH (nolock) 
UNION ALL 
SELECT dbo.versionedfields.id, 
       dbo.versionedfields.itemid, 
       dbo.versionedfields.language, 
       dbo.versionedfields.fieldid, 
       dbo.versionedfields.value, 
       dbo.versionedfields.created, 
       dbo.versionedfields.updated 
FROM   dbo.versionedfields WITH (nolock) 
       INNER JOIN (SELECT itemid, 
                          language, 
                          Max(version) AS Version 
                   FROM   dbo.versionedfields AS VersionedFields_1 WITH (nolock) 
                   GROUP  BY itemid, 
                             language) AS b 
               ON dbo.versionedfields.itemid = b.itemid 
                  AND dbo.versionedfields.language = b.language 
                  AND dbo.versionedfields.version = b.version 

No comments:

Post a Comment