SQL查询未完成

时间:2013-08-02 09:53:38

标签: sql performance

我运行脚本,从表中选择:

SELECT *
FROM [Portfolios]
where Delisted = 0 
  and BrokerAccountId is not null 
  and ImportType = 2
GO

表格的脚本:

CREATE TABLE [dbo].[Portfolios](
    [PortfolioId] [int] IDENTITY(1,1) NOT NULL,
    [UserId] [int] NOT NULL,
    [Guid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [Name] [nvarchar](255) NOT NULL,
    [Notes] [nvarchar](max) NULL,
    [IsDefault] [bit] NOT NULL,
    [Cash] [money] NOT NULL,
    [CurrentCash] [money] NULL,
    [Type] [int] NULL,
    [Delisted] [bit] NOT NULL,
    [CurrencyId] [int] NOT NULL,
    [TrackCashBalanceType] [int] NULL,
    [IsDividendReinvestment] [bit] NOT NULL,
    [ItemId] [int] NULL,
    [FinancialInstitutionId] [int] NULL,
    [Configured] [bit] NULL,
    [BrokerAccountId] [int] NULL,
    [ImportType] [int] NULL,
    [PortfolioTotalValue] [money] NULL,
    [IsRequireNewCredentials] [bit] NOT NULL,
 CONSTRAINT [Portfolios_PK] PRIMARY KEY CLUSTERED 
(
    [PortfolioId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
 CONSTRAINT [Portfolios_uq] UNIQUE NONCLUSTERED 
(
    [Guid] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

通常,此脚本执行大约10秒钟。但现在它还没有完成,但是当我在SQL Server中取消执行查询时,所有需要的数据都被读取。

为什么查询没有完成的任何想法?

1 个答案:

答案 0 :(得分:1)

检查桌子上的锁,

尝试以下查询

SELECT * 来自[TradeStops3]。[dbo]。[Portfolios] / *(NOLOCK)使用此* / 其中Delisted = 0   和BrokerAccountId不为空   和ImportType = 2 GO

如果没有帮助请更新。

此致

Ashutosh Arya