无法在sql中选择多于一行?

时间:2013-11-07 10:40:05

标签: sql-server-2008 tsql

我无法从sql表中选择多于一行。 我只能这样做

Select top 1 * from [table_name] 

Select [pk_table] from [table_name]. 

任何其他命令只是保持处理,表只有大约300条记录,包含10列。

表架构:

CREATE TABLE [dbo].[tb1](
    [myid] [int] IDENTITY(1,1) NOT NULL,
    [cl1] [int] NULL,
    [cl2] [int] NULL,
    [cl3] [varchar](5) NOT NULL,
    [cl4] [varchar](5) NULL,
    [cl5] [tinyint] NULL,

CONSTRAINT [PK_tb1_Tbl] PRIMARY KEY CLUSTERED 
(
    [myid] ASC
)
WITH (PAD_INDEX  = OFF, 
STATISTICS_NORECOMPUTE  = OFF, 
IGNORE_DUP_KEY = OFF,     
ALLOW_ROW_LOCKS  = ON, 
ALLOW_PAGE_LOCKS  = ON) 
ON [PRIMARY]
) ON [PRIMARY] 

由于同一个表模式在其他数据库中工作,我不确定导致此问题的原因。

1 个答案:

答案 0 :(得分:0)

您可以使用以下查询来查找数据库中正在运行的查询:

select
    p.spid
,   right(convert(varchar, 
            dateadd(ms, datediff(ms, P.last_batch, getdate()), '1900-01-01'), 
            121), 12) as 'batch_duration'
,   P.program_name
,   P.hostname
,   P.loginame
from master.dbo.sysprocesses P
where P.spid > 50
and      P.status not in ('background', 'sleeping')
and      P.cmd not in ('AWAITING COMMAND'
                    ,'MIRROR HANDLER'
                    ,'LAZY WRITER'
                    ,'CHECKPOINT SLEEP'
                    ,'RA MANAGER')
order by batch_duration desc