View Single Post
  #16 (permalink)  
Old 11-03-09, 23:47
farax_x farax_x is offline
Registered User
 
Join Date: Sep 2009
Posts: 16
my table :
CREATE TABLE dbo.tblDocument(
docId uniqueidentifier ROWGUIDCOL NOT NULL,
docOrgId int NOT NULL,
docOrgSrvId smallint NOT NULL,
docOwnerDepartmentId uniqueidentifier NOT NULL,
docOwnerPersonnelId uniqueidentifier NOT NULL,
docOwnerName nvarchar(150) NOT NULL,
docDescription nvarchar(max) NOT NULL,
docType smallint NOT NULL,
docNo nvarchar(40) NOT NULL,
docDate char(8) NOT NULL,
docSubject nvarchar(500) NULL,
docSecurityId tinyint NOT NULL,
docUrgencyId tinyint NOT NULL,
docArchiveTotal smallint NOT NULL,
docAttachTotal smallint NOT NULL,
docRegisterTotal smallint NOT NULL,
docRelationTotal smallint NOT NULL,
docSendTotal smallint NOT NULL,
docSignatureTotal smallint NOT NULL,
docTitleTotal smallint NOT NULL,
docDeleteOk bit NOT NULL,
docRegisterDate datetime NOT NULL,
docProperties nvarchar(max) NOT NULL,
docTemplate nvarchar(max) NOT NULL,
docKeyWord nvarchar(300) NOT NULL,
DocAttachType nvarchar(300) NULL,
docOrganizationId uniqueidentifier NOT NULL,
docRegNo varchar(50) NOT NULL,
docRegDate char(8) NOT NULL,
CONSTRAINT PK_tblDocument PRIMARY KEY CLUSTERED
(
docId ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY
)



sample queries :

SELECT * FROM (
SELECT TOP 30 ROW_NUMBER() OVER (ORDER BY docRegisterDate ) as ROW_NUM, DocId,typName, DocSubject,docRegNo,docNo,DocDate,docOwnerName,doc RegisterDate,docType
FROM dbo.tblDocument WITH (NOLOCK)
INNER JOIN (SELECT accDocId, accDepartmentId FROM tblAccess WITH (NOLOCK) GROUP BY accDocId, accDepartmentId) AS tblAccess
ON dbo.tblDocument.docId = tblAccess.accDocId
INNER JOIN IstgRef.dbo.tbrType with (nolock) on tblDocument.docType = tbrType.typId

WHERE docType <> 1002 AND tblAccess.accDepartmentId ='6FCFF50F-012D-436D-B7A1-D9991ADA417F' and docNo LIKE '%123%' and docDate between '13880713' and '13880813' and docSubject LIKE '%test%'
ORDER BY ROW_NUM
)
INNERSELECT
WHERE ROW_NUM > 10

and indexes are create on these columns: docDate,docSubject,docNo,docRegisterDate
Reply With Quote