日期:2014-05-16 浏览次数:20656 次
declare @i int
declare @c int
declare @v nvarchar(100)
declare @result table(
dbname nvarchar(100)
,Error INT
, Level INT
, State INT
, MessageText NVARCHAR (2048)
, RepairLevel NVARCHAR (22)
, Status INT
, DbId INT
, ObjectId INT
, IndexId INT
, PartitionId BIGINT
, AllocUnitId BIGINT
, [File] SMALLINT
, Page INT
, Slot INT
, RefFile SMALLINT
, RefPage INT
, RefSlot INT
, Allocation SMALLINT
)
declare @t table(id int identity(1,1),dbname nvarchar(100))
insert into @t
select Name from sysdatabases
set @i = 1
set @c = (select count(*) from @t)
while(@i<=@c)
begin
select @v = dbname from @t where id = @i
insert into @result(Error, Level, State, MessageText, RepairLevel, Status, DbId, ObjectId, IndexId, PartitionId, AllocUnitId, [File], Page, Slot, RefFile, RefPage, RefSlot, Allocation)
exec('dbcc checkdb ('+@v+') with tableresults')
update @result
set dbname = @v
where dbname is null
set @i = @i + 1
end
--查询dbcc checkdb的结果
select * from @result