--Select dv.FolderID, vn.* from vefn_GetVersionNames () vn join DocVersions dv on vn.versionid = dv.VersionID

declare @FolderID int
set @FolderID = 58 -- Replace with folderid to be removed
Delete From Associations where VersionID in (select versionid from DocVersions where folderid = @FolderID)
Delete From DocVersions where VersionID in (select versionid from DocVersions where folderid= @FolderID)
delete from Folders where folderid=@FolderID