-1

我的应用程序需要从 SQL Server 数据库中获取数据。我的问题是必须将 3 个表连接到一个视图中。这需要很长时间(生成视图大约需要 30 秒)所以我想知道是否有办法优化这个 SQL 查询?

SQL查询:

SELECT TOP (100) PERCENT Request1.RequestID,
                         TrackIT.dbo.Sending.Barcode,
                         TrackIT.dbo.Address_View.AdrID,
                         TrackIT.dbo.Address_View.Name,
                         TrackIT.dbo.Address_View.Street,
                         TrackIT.dbo.Address_View.HouseNo,
                         TrackIT.dbo.Address_View.Postal,
                         TrackIT.dbo.Address_View.City,
                         TrackIT.dbo.Address_View.Country,
                         Request1.Latitude,
                         Request1.Longitude,
                         Request1.ReceivedDate
FROM   (SELECT DISTINCT RequestID,
                        Ltrim([Content]) AS Barcode,
                        Latitude,
                        Longitude,
                        ReceivedDate
        FROM   RequestWithLocation
        WHERE  ( Site LIKE '%Z' )
               AND ( [Content] <> '' )
               AND ( AddressID = '0' )
               AND ReceivedDate > Dateadd(day, -7, Getdate())) AS Request1
       INNER JOIN TrackIT.dbo.Sending
         ON Request1.Barcode = TrackIT.dbo.Sending.Barcode
       INNER JOIN TrackIT.dbo.Address_View
         ON TrackIT.dbo.Sending.DeliveryAdrID = TrackIT.dbo.Address_View.AdrID
ORDER  BY AdrID 

任何人都可以帮忙吗?

4

2 回答 2

0

您应该将连接字段上的索引添加到表中。

于 2012-11-05T12:18:58.500 回答
-1

嗨,你能试试索引视图吗

供参考:http ://technet.microsoft.com/en-US/library/cc917715.aspx

于 2012-11-05T07:19:23.910 回答