I don't know how to get the PRINT statements flushed to QA, either (although
you might try setting your network packet size very, very small but this is
fraught with peril) but if one wants to know how far along the reindexing
process is, I have two suggestions that may work:
1. Examine the syslockinfo tables to see what's got an exclusive lock for
your connection. Mapping to table names is reasonably straightforward.
2. Create an in-progess table and update it as you go along. Since this
is informational and not business critical, you wouldn't need any particular
transaction management. You could even do things rather differently
altogether. The following is kinda/sorta tested:
Select so.name, 'N' as status into ReindexList from sysobjects so where
so.type = 'U' and so.name <> 'ReindexList' /* maybe include a restriction to
DBO-only tables, too, or include the owner here and as part of the PK */
go
alter table ReindexList add constraint PK_ReindexList primary key clustered
(name)
go
DECLARE @TableName varchar(255)
DECLARE ReindexTableCursor CURSOR FOR
SELECT name FROM ReindexList
where status <> 'C'
ORDER BY name
for update of status
OPEN ReindexTableCursor
-- Perform the first fetch.
FETCH NEXT FROM ReindexTableCursor INTO @TableName
-- Check @@FETCH_STATUS to see if there are any rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
-- This is executed as long as the previous fetch succeeds.
PRINT 'Reindexing' + ' ' + @TableName
update ReindexList set status = 'P' where current of ReindexTableCursor /*
P for processing */
DBCC DBREINDEX (@TableName )
update ReindexList set status = 'C' where current of ReindexTableCursor /*
C for completed */
FETCH NEXT FROM ReindexTableCursor into @TableName
END
CLOSE ReindexTableCursor
DEALLOCATE ReindexTableCursor
go
While the process is in progress, one should be able to query the
ReindexList table and see the statuses. I say "should" because I commented
out the actual reindex statement and this didn't take long enough for me to
query the table. I suppose I could add a waitfor and do some poking
around... Well, not today.
Notice that using the in-progress table means that one could interrupt this
and come back to it later without redoing work already done. I already
included the <> 'C' restriction.
[quoted text, click to view] "Andrew J. Kelly" <sqlmvpnooospam@shadhawk.com> wrote in message
news:exIt6JzbEHA.2476@TK2MSFTNGP09.phx.gbl...
> That is due to the way it buffers the output and there is no easy way to
do
> what your asking that I know of. It is something that a lot of people ask
> about but I haven't seen a good solution.
>
> --
> Andrew J. Kelly SQL MVP
>
>
> "Dave Mortenson" <dmortenson@dentrix.com> wrote in message
> news:O0Bp86ybEHA.2944@TK2MSFTNGP11.phx.gbl...
> > Andrew Excellent that is what I wanted to know. Thank you so much. Do
you
> > know of a way to make it print as it completes each execution rather
than
> > all at the end? I do use the print command but like I said it will only
> > print all at the end.
> >
> > THanks again I really appreciate the info.
> >
> > Dave
> >
> >
[snip]