22,209
社区成员
发帖
与我相关
我的任务
分享
SELECT i.id,
i.Url,
i.ServicePath,
p.ProductName,
s.Name AS sName,
p.Brand,
p.ASIN,
p.Country,
p.Price
FROM Product_Images i
LEFT JOIN Product p
ON i.ProductGuid = p.ProductGuid
LEFT JOIN Store s
ON p.StoreGuid = s.StoreGuid
WHERE 1 = 1
ORDER BY i.id
OFFSET 0 ROWS
FETCH NEXT 10 ROWS ONLY;
--删除无用的索引。因为主键本身也是索引,没必要再建立
DROP INDEX IX_Product_Images ON Product_Images
DROP INDEX IX_Product ON Product
--连接字段增加索引
CREATE INDEX IX_Product_Images_ProductGuid ON Product_Images(ProductGuid);
CREATE INDEX IX_Product_ProductGuid ON Product(ProductGuid);
CREATE INDEX IX_Product_StoreGuid ON Product(StoreGuid);
CREATE INDEX IX_Store_StoreGuid ON Store(StoreGuid);
EXEC sp_spaceused 'Product_Images'
EXEC sp_spaceused 'Product'
EXEC sp_spaceused 'Store'
EXEC sp_helpindex 'Product_Images'
EXEC sp_helpindex 'Product'
EXEC sp_helpindex 'Store'
DECLARE @pageIndex INT,@pageSize INT
SET @pageIndex=1
SET @pageSize=10
SELECT i.id,
i.Url,
i.ServicePath,
p.ProductName,
s.Name AS sName,
p.Brand,
p.ASIN,
p.Country,
p.Price
FROM Product_Images i
LEFT JOIN Product p
ON i.ProductGuid = p.ProductGuid
LEFT JOIN Store s
ON p.StoreGuid = s.StoreGuid
WHERE 1 = 1
ORDER BY i.id
OFFSET (@pageIndex-1)*@pageSize ROWS
FETCH NEXT @pageSize ROWS ONLY;
SELECT * FROM (
SELECT i.id,
i.Url,
i.ServicePath,
p.ProductName,
s.Name AS sName,
p.Brand,
p.ASIN,
p.Country,
p.Price,
ROW_NUMBER() OVER (ORDER BY id) AS rid
FROM Product_Images i
LEFT JOIN Product p
ON i.ProductGuid = p.ProductGuid
LEFT JOIN Store s
ON p.StoreGuid = s.StoreGuid
WHERE 1 = 1
) AS t
WHERE t.rid>0 AND t.rid<=10
[/quote]SELECT * FROM (
SELECT i.id,
i.Url,
i.ServicePath,
p.ProductName,
s.Name AS sName,
p.Brand,
p.ASIN,
p.Country,
p.Price,
ROW_NUMBER() OVER (ORDER BY id) AS rid
FROM Product_Images i
LEFT JOIN Product p
ON i.ProductGuid = p.ProductGuid
LEFT JOIN Store s
ON p.StoreGuid = s.StoreGuid
WHERE 1 = 1
) AS t
WHERE t.rid>0 AND t.rid<=10