只有代码不能说从哪里优化好。根据实际,对相应的表建立合适的索引来达到提高查询效率。
还有就是in ()可以考虑使用EXISTS() 
NOT IN()可以考虑使用NOT EXISTS()

解决方案 »

  1.   

    还有下面一个:CREATE Procedure [dbo].cs_Section_Get
    (
    @SettingsID int,
    @SectionID int,
    @ApplicationKey nvarchar(512) = null,
    @ApplicationType smallint
    )as
    SET Transaction Isolation Level Read UNCOMMITTEDif(@ApplicationKey is not null)
    Begin
    Select @SectionID = SectionID FROM cs_Sections where ApplicationKey = @ApplicationKey and ApplicationType = @ApplicationType
    EndSELECT 
    SectionID, SettingsID, IsActive, ParentID, GroupID, [Name], NewsgroupName, [Description], 
    DateCreated, Url, IsModerated, DaysToView, SortOrder, TotalPosts, TotalThreads, DisplayMask, 
    EnablePostStatistics, EnablePostPoints, EnableAutoDelete, EnableAnonymousPosting, AutoDeleteThreshold, 
    MostRecentPostID, MostRecentThreadID, MostRecentThreadReplies, MostRecentPostSubject, 
    MostRecentPostAuthor, MostRecentPostAuthorID, MostRecentPostDate, PostsToModerate, ForumType, 
    IsSearchable, ApplicationType, ApplicationKey, PropertyNames as SectionPropertyNames, PropertyValues as SectionPropertyValues, Path, DefaultLanguage
    FROM 
    cs_Sections 
    Where SectionID = @SectionID and ApplicationType = @ApplicationTypeexec cs_Section_Permissions_Get @SettingsID, @SectionID, @ApplicationTypeGO