sql2k sp3a
Not really any more to ask.
TIA, ChrisR
Yes. Shared locks are put up when you run it. Try using WITH FAST and do
only one table at a time. You get less info, but it's the stuff you need.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"ChrisR" <noemail@.bla.com> wrote in message
news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
sql2k sp3a
Not really any more to ask.
TIA, ChrisR
Showing posts with label dbcc. Show all posts
Showing posts with label dbcc. Show all posts
Thursday, March 8, 2012
can dbcc showcontig slow things down/ lock tables?
sql2k sp3a
Not really any more to ask.
TIA, ChrisRYes. Shared locks are put up when you run it. Try using WITH FAST and do
only one table at a time. You get less info, but it's the stuff you need.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"ChrisR" <noemail@.bla.com> wrote in message
news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
sql2k sp3a
Not really any more to ask.
TIA, ChrisR
Not really any more to ask.
TIA, ChrisRYes. Shared locks are put up when you run it. Try using WITH FAST and do
only one table at a time. You get less info, but it's the stuff you need.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"ChrisR" <noemail@.bla.com> wrote in message
news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
sql2k sp3a
Not really any more to ask.
TIA, ChrisR
can dbcc showcontig slow things down/ lock tables?
sql2k sp3a
Not really any more to ask.
TIA, ChrisRYes. Shared locks are put up when you run it. Try using WITH FAST and do
only one table at a time. You get less info, but it's the stuff you need.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"ChrisR" <noemail@.bla.com> wrote in message
news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
sql2k sp3a
Not really any more to ask.
TIA, ChrisR
Not really any more to ask.
TIA, ChrisRYes. Shared locks are put up when you run it. Try using WITH FAST and do
only one table at a time. You get less info, but it's the stuff you need.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"ChrisR" <noemail@.bla.com> wrote in message
news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
sql2k sp3a
Not really any more to ask.
TIA, ChrisR
can dbcc showcontig slow things down/ lock tables cont'd
Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that
they will be locked for a shorter period of time?
TIA, ChrisR
Yes. Shared locks are put up when you run it. Try using WITH FAST and do
only one table at a time. You get less info, but it's the stuff you need.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"ChrisR" <noemail@.bla.com> wrote in message
news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
sql2k sp3a
Not really any more to ask.
TIA, ChrisR" A fast scan does not read the leaf or data level pages of the index. "
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_dbcc_46cn.asp
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"ChrisR" <noemail@.bla.com> wrote in message
news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that
> they will be locked for a shorter period of time?
> TIA, ChrisR
>
>
> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
> only one table at a time. You get less info, but it's the stuff you need.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> sql2k sp3a
> Not really any more to ask.
> TIA, ChrisR
>
>|||Thanks Adam. I saw that, and the way I read it is that it won't lock my
tables up. But before I fire this off in production during the middle of the
day, I wanted to confirm my thoughts?
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:uCIS9nMqFHA.208@.TK2MSFTNGP10.phx.gbl...
>" A fast scan does not read the leaf or data level pages of the index. "
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_dbcc_46cn.asp
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.datamanipulation.net
> --
>
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
>> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that
>> they will be locked for a shorter period of time?
>> TIA, ChrisR
>>
>>
>> Yes. Shared locks are put up when you run it. Try using WITH FAST and
>> do
>> only one table at a time. You get less info, but it's the stuff you
>> need.
>> --
>> Tom
>> ----
>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
>> SQL Server MVP
>> Columnist, SQL Server Professional
>> Toronto, ON Canada
>> www.pinpub.com
>> .
>> "ChrisR" <noemail@.bla.com> wrote in message
>> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
>> sql2k sp3a
>> Not really any more to ask.
>> TIA, ChrisR
>>
>|||FAST makes the operation faster as the leaf level doesn't have to be read. As for locking FAST
doesn't make a difference (table S lock). For non-heaps, you will have table IS lock instead when
using FAST.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"ChrisR" <noemail@.bla.com> wrote in message news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that they will be locked for a
> shorter period of time?
> TIA, ChrisR
>
>
> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
> only one table at a time. You get less info, but it's the stuff you need.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> sql2k sp3a
> Not really any more to ask.
> TIA, ChrisR
>
>|||It will still acquire shared locks.
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"ChrisR" <noemail@.bla.com> wrote in message
news:umO5mqMqFHA.1028@.TK2MSFTNGP09.phx.gbl...
> Thanks Adam. I saw that, and the way I read it is that it won't lock my
> tables up. But before I fire this off in production during the middle of
the
> day, I wanted to confirm my thoughts?
>
> "Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
> news:uCIS9nMqFHA.208@.TK2MSFTNGP10.phx.gbl...
> >" A fast scan does not read the leaf or data level pages of the index. "
> >
> >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_dbcc_46cn.asp
> >
> >
> > --
> > Adam Machanic
> > SQL Server MVP
> > http://www.datamanipulation.net
> > --
> >
> >
> > "ChrisR" <noemail@.bla.com> wrote in message
> > news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
> >> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or
that
> >> they will be locked for a shorter period of time?
> >>
> >> TIA, ChrisR
> >>
> >>
> >>
> >>
> >>
> >> Yes. Shared locks are put up when you run it. Try using WITH FAST and
> >> do
> >> only one table at a time. You get less info, but it's the stuff you
> >> need.
> >>
> >> --
> >> Tom
> >>
> >> ----
> >> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> >> SQL Server MVP
> >> Columnist, SQL Server Professional
> >> Toronto, ON Canada
> >> www.pinpub.com
> >> .
> >> "ChrisR" <noemail@.bla.com> wrote in message
> >> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> >> sql2k sp3a
> >>
> >> Not really any more to ask.
> >>
> >> TIA, ChrisR
> >>
> >>
> >>
> >
> >
>|||Oops, a mistake in my post:
For heaps, FAST doesn't make difference (S table lock).
For non-heaps, FAST takes table IS instead of table S.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in message
news:OJs0rsMqFHA.3576@.TK2MSFTNGP09.phx.gbl...
> FAST makes the operation faster as the leaf level doesn't have to be read. As for locking FAST
> doesn't make a difference (table S lock). For non-heaps, you will have table IS lock instead when
> using FAST.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "ChrisR" <noemail@.bla.com> wrote in message news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
>> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that they will be locked for
>> a shorter period of time?
>> TIA, ChrisR
>>
>>
>> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
>> only one table at a time. You get less info, but it's the stuff you need.
>> --
>> Tom
>> ----
>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
>> SQL Server MVP
>> Columnist, SQL Server Professional
>> Toronto, ON Canada
>> www.pinpub.com
>> .
>> "ChrisR" <noemail@.bla.com> wrote in message
>> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
>> sql2k sp3a
>> Not really any more to ask.
>> TIA, ChrisR
>>
>
they will be locked for a shorter period of time?
TIA, ChrisR
Yes. Shared locks are put up when you run it. Try using WITH FAST and do
only one table at a time. You get less info, but it's the stuff you need.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"ChrisR" <noemail@.bla.com> wrote in message
news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
sql2k sp3a
Not really any more to ask.
TIA, ChrisR" A fast scan does not read the leaf or data level pages of the index. "
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_dbcc_46cn.asp
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"ChrisR" <noemail@.bla.com> wrote in message
news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that
> they will be locked for a shorter period of time?
> TIA, ChrisR
>
>
> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
> only one table at a time. You get less info, but it's the stuff you need.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> sql2k sp3a
> Not really any more to ask.
> TIA, ChrisR
>
>|||Thanks Adam. I saw that, and the way I read it is that it won't lock my
tables up. But before I fire this off in production during the middle of the
day, I wanted to confirm my thoughts?
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:uCIS9nMqFHA.208@.TK2MSFTNGP10.phx.gbl...
>" A fast scan does not read the leaf or data level pages of the index. "
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_dbcc_46cn.asp
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.datamanipulation.net
> --
>
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
>> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that
>> they will be locked for a shorter period of time?
>> TIA, ChrisR
>>
>>
>> Yes. Shared locks are put up when you run it. Try using WITH FAST and
>> do
>> only one table at a time. You get less info, but it's the stuff you
>> need.
>> --
>> Tom
>> ----
>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
>> SQL Server MVP
>> Columnist, SQL Server Professional
>> Toronto, ON Canada
>> www.pinpub.com
>> .
>> "ChrisR" <noemail@.bla.com> wrote in message
>> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
>> sql2k sp3a
>> Not really any more to ask.
>> TIA, ChrisR
>>
>|||FAST makes the operation faster as the leaf level doesn't have to be read. As for locking FAST
doesn't make a difference (table S lock). For non-heaps, you will have table IS lock instead when
using FAST.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"ChrisR" <noemail@.bla.com> wrote in message news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that they will be locked for a
> shorter period of time?
> TIA, ChrisR
>
>
> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
> only one table at a time. You get less info, but it's the stuff you need.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> sql2k sp3a
> Not really any more to ask.
> TIA, ChrisR
>
>|||It will still acquire shared locks.
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"ChrisR" <noemail@.bla.com> wrote in message
news:umO5mqMqFHA.1028@.TK2MSFTNGP09.phx.gbl...
> Thanks Adam. I saw that, and the way I read it is that it won't lock my
> tables up. But before I fire this off in production during the middle of
the
> day, I wanted to confirm my thoughts?
>
> "Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
> news:uCIS9nMqFHA.208@.TK2MSFTNGP10.phx.gbl...
> >" A fast scan does not read the leaf or data level pages of the index. "
> >
> >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_dbcc_46cn.asp
> >
> >
> > --
> > Adam Machanic
> > SQL Server MVP
> > http://www.datamanipulation.net
> > --
> >
> >
> > "ChrisR" <noemail@.bla.com> wrote in message
> > news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
> >> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or
that
> >> they will be locked for a shorter period of time?
> >>
> >> TIA, ChrisR
> >>
> >>
> >>
> >>
> >>
> >> Yes. Shared locks are put up when you run it. Try using WITH FAST and
> >> do
> >> only one table at a time. You get less info, but it's the stuff you
> >> need.
> >>
> >> --
> >> Tom
> >>
> >> ----
> >> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> >> SQL Server MVP
> >> Columnist, SQL Server Professional
> >> Toronto, ON Canada
> >> www.pinpub.com
> >> .
> >> "ChrisR" <noemail@.bla.com> wrote in message
> >> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> >> sql2k sp3a
> >>
> >> Not really any more to ask.
> >>
> >> TIA, ChrisR
> >>
> >>
> >>
> >
> >
>|||Oops, a mistake in my post:
For heaps, FAST doesn't make difference (S table lock).
For non-heaps, FAST takes table IS instead of table S.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in message
news:OJs0rsMqFHA.3576@.TK2MSFTNGP09.phx.gbl...
> FAST makes the operation faster as the leaf level doesn't have to be read. As for locking FAST
> doesn't make a difference (table S lock). For non-heaps, you will have table IS lock instead when
> using FAST.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "ChrisR" <noemail@.bla.com> wrote in message news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
>> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that they will be locked for
>> a shorter period of time?
>> TIA, ChrisR
>>
>>
>> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
>> only one table at a time. You get less info, but it's the stuff you need.
>> --
>> Tom
>> ----
>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
>> SQL Server MVP
>> Columnist, SQL Server Professional
>> Toronto, ON Canada
>> www.pinpub.com
>> .
>> "ChrisR" <noemail@.bla.com> wrote in message
>> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
>> sql2k sp3a
>> Not really any more to ask.
>> TIA, ChrisR
>>
>
can dbcc showcontig slow things down/ lock tables cont'd
Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that
they will be locked for a shorter period of time?
TIA, ChrisR
Yes. Shared locks are put up when you run it. Try using WITH FAST and do
only one table at a time. You get less info, but it's the stuff you need.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"ChrisR" <noemail@.bla.com> wrote in message
news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
sql2k sp3a
Not really any more to ask.
TIA, ChrisR
" A fast scan does not read the leaf or data level pages of the index. "
http://msdn.microsoft.com/library/de..._dbcc_46cn.asp
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
"ChrisR" <noemail@.bla.com> wrote in message
news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that
> they will be locked for a shorter period of time?
> TIA, ChrisR
>
>
> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
> only one table at a time. You get less info, but it's the stuff you need.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> sql2k sp3a
> Not really any more to ask.
> TIA, ChrisR
>
>
|||Thanks Adam. I saw that, and the way I read it is that it won't lock my
tables up. But before I fire this off in production during the middle of the
day, I wanted to confirm my thoughts?
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:uCIS9nMqFHA.208@.TK2MSFTNGP10.phx.gbl...
>" A fast scan does not read the leaf or data level pages of the index. "
> http://msdn.microsoft.com/library/de..._dbcc_46cn.asp
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.datamanipulation.net
> --
>
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
>
|||FAST makes the operation faster as the leaf level doesn't have to be read. As for locking FAST
doesn't make a difference (table S lock). For non-heaps, you will have table IS lock instead when
using FAST.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"ChrisR" <noemail@.bla.com> wrote in message news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that they will be locked for a
> shorter period of time?
> TIA, ChrisR
>
>
> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
> only one table at a time. You get less info, but it's the stuff you need.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> sql2k sp3a
> Not really any more to ask.
> TIA, ChrisR
>
>
|||It will still acquire shared locks.
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
"ChrisR" <noemail@.bla.com> wrote in message
news:umO5mqMqFHA.1028@.TK2MSFTNGP09.phx.gbl...
> Thanks Adam. I saw that, and the way I read it is that it won't lock my
> tables up. But before I fire this off in production during the middle of
the[vbcol=seagreen]
> day, I wanted to confirm my thoughts?
>
> "Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
> news:uCIS9nMqFHA.208@.TK2MSFTNGP10.phx.gbl...
http://msdn.microsoft.com/library/de..._dbcc_46cn.asp[vbcol=seagreen]
that
>
|||Oops, a mistake in my post:
For heaps, FAST doesn't make difference (S table lock).
For non-heaps, FAST takes table IS instead of table S.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in message
news:OJs0rsMqFHA.3576@.TK2MSFTNGP09.phx.gbl...
> FAST makes the operation faster as the leaf level doesn't have to be read. As for locking FAST
> doesn't make a difference (table S lock). For non-heaps, you will have table IS lock instead when
> using FAST.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "ChrisR" <noemail@.bla.com> wrote in message news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
>
they will be locked for a shorter period of time?
TIA, ChrisR
Yes. Shared locks are put up when you run it. Try using WITH FAST and do
only one table at a time. You get less info, but it's the stuff you need.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"ChrisR" <noemail@.bla.com> wrote in message
news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
sql2k sp3a
Not really any more to ask.
TIA, ChrisR
" A fast scan does not read the leaf or data level pages of the index. "
http://msdn.microsoft.com/library/de..._dbcc_46cn.asp
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
"ChrisR" <noemail@.bla.com> wrote in message
news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that
> they will be locked for a shorter period of time?
> TIA, ChrisR
>
>
> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
> only one table at a time. You get less info, but it's the stuff you need.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> sql2k sp3a
> Not really any more to ask.
> TIA, ChrisR
>
>
|||Thanks Adam. I saw that, and the way I read it is that it won't lock my
tables up. But before I fire this off in production during the middle of the
day, I wanted to confirm my thoughts?
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:uCIS9nMqFHA.208@.TK2MSFTNGP10.phx.gbl...
>" A fast scan does not read the leaf or data level pages of the index. "
> http://msdn.microsoft.com/library/de..._dbcc_46cn.asp
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.datamanipulation.net
> --
>
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
>
|||FAST makes the operation faster as the leaf level doesn't have to be read. As for locking FAST
doesn't make a difference (table S lock). For non-heaps, you will have table IS lock instead when
using FAST.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"ChrisR" <noemail@.bla.com> wrote in message news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that they will be locked for a
> shorter period of time?
> TIA, ChrisR
>
>
> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
> only one table at a time. You get less info, but it's the stuff you need.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> sql2k sp3a
> Not really any more to ask.
> TIA, ChrisR
>
>
|||It will still acquire shared locks.
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
"ChrisR" <noemail@.bla.com> wrote in message
news:umO5mqMqFHA.1028@.TK2MSFTNGP09.phx.gbl...
> Thanks Adam. I saw that, and the way I read it is that it won't lock my
> tables up. But before I fire this off in production during the middle of
the[vbcol=seagreen]
> day, I wanted to confirm my thoughts?
>
> "Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
> news:uCIS9nMqFHA.208@.TK2MSFTNGP10.phx.gbl...
http://msdn.microsoft.com/library/de..._dbcc_46cn.asp[vbcol=seagreen]
that
>
|||Oops, a mistake in my post:
For heaps, FAST doesn't make difference (S table lock).
For non-heaps, FAST takes table IS instead of table S.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in message
news:OJs0rsMqFHA.3576@.TK2MSFTNGP09.phx.gbl...
> FAST makes the operation faster as the leaf level doesn't have to be read. As for locking FAST
> doesn't make a difference (table S lock). For non-heaps, you will have table IS lock instead when
> using FAST.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "ChrisR" <noemail@.bla.com> wrote in message news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
>
can dbcc showcontig slow things down/ lock tables cont'd
Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that
they will be locked for a shorter period of time?
TIA, ChrisR
Yes. Shared locks are put up when you run it. Try using WITH FAST and do
only one table at a time. You get less info, but it's the stuff you need.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"ChrisR" <noemail@.bla.com> wrote in message
news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
sql2k sp3a
Not really any more to ask.
TIA, ChrisR" A fast scan does not read the leaf or data level pages of the index. "
http://msdn.microsoft.com/library/d...
6cn.asp
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"ChrisR" <noemail@.bla.com> wrote in message
news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that
> they will be locked for a shorter period of time?
> TIA, ChrisR
>
>
> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
> only one table at a time. You get less info, but it's the stuff you need.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> sql2k sp3a
> Not really any more to ask.
> TIA, ChrisR
>
>|||Thanks Adam. I saw that, and the way I read it is that it won't lock my
tables up. But before I fire this off in production during the middle of the
day, I wanted to confirm my thoughts?
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:uCIS9nMqFHA.208@.TK2MSFTNGP10.phx.gbl...
>" A fast scan does not read the leaf or data level pages of the index. "
> http://msdn.microsoft.com/library/d...r />
_46cn.asp
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.datamanipulation.net
> --
>
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
>|||FAST makes the operation faster as the leaf level doesn't have to be read. A
s for locking FAST
doesn't make a difference (table S lock). For non-heaps, you will have table
IS lock instead when
using FAST.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"ChrisR" <noemail@.bla.com> wrote in message news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...[vbc
ol=seagreen]
> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that t
hey will be locked for a
> shorter period of time?
> TIA, ChrisR
>
>
> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
> only one table at a time. You get less info, but it's the stuff you need.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> sql2k sp3a
> Not really any more to ask.
> TIA, ChrisR
>
>[/vbcol]|||It will still acquire shared locks.
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"ChrisR" <noemail@.bla.com> wrote in message
news:umO5mqMqFHA.1028@.TK2MSFTNGP09.phx.gbl...
> Thanks Adam. I saw that, and the way I read it is that it won't lock my
> tables up. But before I fire this off in production during the middle of
the
> day, I wanted to confirm my thoughts?
>
> "Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
> news:uCIS9nMqFHA.208@.TK2MSFTNGP10.phx.gbl...
http://msdn.microsoft.com/library/d...s_dbcc_46cn.asp[vb
col=seagreen]
that[vbcol=seagreen]
>|||Oops, a mistake in my post:
For heaps, FAST doesn't make difference (S table lock).
For non-heaps, FAST takes table IS instead of table S.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message
news:OJs0rsMqFHA.3576@.TK2MSFTNGP09.phx.gbl...
> FAST makes the operation faster as the leaf level doesn't have to be read.
As for locking FAST
> doesn't make a difference (table S lock). For non-heaps, you will have tab
le IS lock instead when
> using FAST.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "ChrisR" <noemail@.bla.com> wrote in message news:OgEFzkMqFHA.544@.TK2MSFTNG
P11.phx.gbl...
>
they will be locked for a shorter period of time?
TIA, ChrisR
Yes. Shared locks are put up when you run it. Try using WITH FAST and do
only one table at a time. You get less info, but it's the stuff you need.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"ChrisR" <noemail@.bla.com> wrote in message
news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
sql2k sp3a
Not really any more to ask.
TIA, ChrisR" A fast scan does not read the leaf or data level pages of the index. "
http://msdn.microsoft.com/library/d...
6cn.asp
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"ChrisR" <noemail@.bla.com> wrote in message
news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that
> they will be locked for a shorter period of time?
> TIA, ChrisR
>
>
> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
> only one table at a time. You get less info, but it's the stuff you need.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> sql2k sp3a
> Not really any more to ask.
> TIA, ChrisR
>
>|||Thanks Adam. I saw that, and the way I read it is that it won't lock my
tables up. But before I fire this off in production during the middle of the
day, I wanted to confirm my thoughts?
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:uCIS9nMqFHA.208@.TK2MSFTNGP10.phx.gbl...
>" A fast scan does not read the leaf or data level pages of the index. "
> http://msdn.microsoft.com/library/d...r />
_46cn.asp
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.datamanipulation.net
> --
>
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...
>|||FAST makes the operation faster as the leaf level doesn't have to be read. A
s for locking FAST
doesn't make a difference (table S lock). For non-heaps, you will have table
IS lock instead when
using FAST.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"ChrisR" <noemail@.bla.com> wrote in message news:OgEFzkMqFHA.544@.TK2MSFTNGP11.phx.gbl...[vbc
ol=seagreen]
> Thanks Tom. Does WITH FAST mean that the tables won't be locked, or that t
hey will be locked for a
> shorter period of time?
> TIA, ChrisR
>
>
> Yes. Shared locks are put up when you run it. Try using WITH FAST and do
> only one table at a time. You get less info, but it's the stuff you need.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "ChrisR" <noemail@.bla.com> wrote in message
> news:OJY7r9BqFHA.2588@.TK2MSFTNGP12.phx.gbl...
> sql2k sp3a
> Not really any more to ask.
> TIA, ChrisR
>
>[/vbcol]|||It will still acquire shared locks.
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"ChrisR" <noemail@.bla.com> wrote in message
news:umO5mqMqFHA.1028@.TK2MSFTNGP09.phx.gbl...
> Thanks Adam. I saw that, and the way I read it is that it won't lock my
> tables up. But before I fire this off in production during the middle of
the
> day, I wanted to confirm my thoughts?
>
> "Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
> news:uCIS9nMqFHA.208@.TK2MSFTNGP10.phx.gbl...
http://msdn.microsoft.com/library/d...s_dbcc_46cn.asp[vb
col=seagreen]
that[vbcol=seagreen]
>|||Oops, a mistake in my post:
For heaps, FAST doesn't make difference (S table lock).
For non-heaps, FAST takes table IS instead of table S.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message
news:OJs0rsMqFHA.3576@.TK2MSFTNGP09.phx.gbl...
> FAST makes the operation faster as the leaf level doesn't have to be read.
As for locking FAST
> doesn't make a difference (table S lock). For non-heaps, you will have tab
le IS lock instead when
> using FAST.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "ChrisR" <noemail@.bla.com> wrote in message news:OgEFzkMqFHA.544@.TK2MSFTNG
P11.phx.gbl...
>
can dbcc inputbuffer show parameterized queries?
Hi,
I'm trying to capture blocking information on my SQL Server 2k box and
running dbcc inputbuffer only shows me the "sp_executesql" command, it
doesn't show me the parameters which is the actual sql. Profiler seems to
have no problem showing the parameters b/c it always shows me the sql that's
running, not the sp_executesql command. Is there some other command that
will pull the sql from a parameterized query a la Profiler? Thanks for any
help here.
lc
LC,
Have you tried using fn_get_sql()? (Although for sp_executesql I usually
get nothing unless a stored procedure is being executed.)
RLF
"LC" <LC@.discussions.microsoft.com> wrote in message
news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
> Hi,
> I'm trying to capture blocking information on my SQL Server 2k box and
> running dbcc inputbuffer only shows me the "sp_executesql" command, it
> doesn't show me the parameters which is the actual sql. Profiler seems to
> have no problem showing the parameters b/c it always shows me the sql
> that's
> running, not the sp_executesql command. Is there some other command that
> will pull the sql from a parameterized query a la Profiler? Thanks for
> any
> help here.
> lc
|||I've tried that function, but all of the sql handles in my databases are
0x000000... Since all of the sql handles are the same (all zero's), I'm not
getting any useful information.
"Russell Fields" wrote:
> LC,
> Have you tried using fn_get_sql()? (Although for sp_executesql I usually
> get nothing unless a stored procedure is being executed.)
> RLF
> "LC" <LC@.discussions.microsoft.com> wrote in message
> news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
>
>
|||LC
Dbcc inputbuffer shows the last command to execute through the connection.
Fn_get_sql only can work for a statement that is running _right_now_, since
as soon as a statement is complete the handle returns to 0. Therefore, most
of your sql handles should be zero, but not is a stored procedure is
actually running at the moment.
FWIW - RLF
"LC" <LC@.discussions.microsoft.com> wrote in message
news:6D105C91-1A27-413A-8117-6619CDDE76C4@.microsoft.com...[vbcol=seagreen]
> I've tried that function, but all of the sql handles in my databases are
> 0x000000... Since all of the sql handles are the same (all zero's), I'm
> not
> getting any useful information.
> "Russell Fields" wrote:
I'm trying to capture blocking information on my SQL Server 2k box and
running dbcc inputbuffer only shows me the "sp_executesql" command, it
doesn't show me the parameters which is the actual sql. Profiler seems to
have no problem showing the parameters b/c it always shows me the sql that's
running, not the sp_executesql command. Is there some other command that
will pull the sql from a parameterized query a la Profiler? Thanks for any
help here.
lc
LC,
Have you tried using fn_get_sql()? (Although for sp_executesql I usually
get nothing unless a stored procedure is being executed.)
RLF
"LC" <LC@.discussions.microsoft.com> wrote in message
news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
> Hi,
> I'm trying to capture blocking information on my SQL Server 2k box and
> running dbcc inputbuffer only shows me the "sp_executesql" command, it
> doesn't show me the parameters which is the actual sql. Profiler seems to
> have no problem showing the parameters b/c it always shows me the sql
> that's
> running, not the sp_executesql command. Is there some other command that
> will pull the sql from a parameterized query a la Profiler? Thanks for
> any
> help here.
> lc
|||I've tried that function, but all of the sql handles in my databases are
0x000000... Since all of the sql handles are the same (all zero's), I'm not
getting any useful information.
"Russell Fields" wrote:
> LC,
> Have you tried using fn_get_sql()? (Although for sp_executesql I usually
> get nothing unless a stored procedure is being executed.)
> RLF
> "LC" <LC@.discussions.microsoft.com> wrote in message
> news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
>
>
|||LC
Dbcc inputbuffer shows the last command to execute through the connection.
Fn_get_sql only can work for a statement that is running _right_now_, since
as soon as a statement is complete the handle returns to 0. Therefore, most
of your sql handles should be zero, but not is a stored procedure is
actually running at the moment.
FWIW - RLF
"LC" <LC@.discussions.microsoft.com> wrote in message
news:6D105C91-1A27-413A-8117-6619CDDE76C4@.microsoft.com...[vbcol=seagreen]
> I've tried that function, but all of the sql handles in my databases are
> 0x000000... Since all of the sql handles are the same (all zero's), I'm
> not
> getting any useful information.
> "Russell Fields" wrote:
Labels:
andrunning,
blocking,
box,
capture,
command,
database,
dbcc,
inputbuffer,
microsoft,
mysql,
oracle,
parameterized,
queries,
server,
sp_executesql,
sql
can dbcc inputbuffer show parameterized queries?
Hi,
I'm trying to capture blocking information on my SQL Server 2k box and
running dbcc inputbuffer only shows me the "sp_executesql" command, it
doesn't show me the parameters which is the actual sql. Profiler seems to
have no problem showing the parameters b/c it always shows me the sql that's
running, not the sp_executesql command. Is there some other command that
will pull the sql from a parameterized query a la Profiler? Thanks for any
help here.
lcLC,
Have you tried using fn_get_sql()? (Although for sp_executesql I usually
get nothing unless a stored procedure is being executed.)
RLF
"LC" <LC@.discussions.microsoft.com> wrote in message
news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
> Hi,
> I'm trying to capture blocking information on my SQL Server 2k box and
> running dbcc inputbuffer only shows me the "sp_executesql" command, it
> doesn't show me the parameters which is the actual sql. Profiler seems to
> have no problem showing the parameters b/c it always shows me the sql
> that's
> running, not the sp_executesql command. Is there some other command that
> will pull the sql from a parameterized query a la Profiler? Thanks for
> any
> help here.
> lc|||I've tried that function, but all of the sql handles in my databases are
0x000000... Since all of the sql handles are the same (all zero's), I'm not
getting any useful information.
"Russell Fields" wrote:
> LC,
> Have you tried using fn_get_sql()? (Although for sp_executesql I usually
> get nothing unless a stored procedure is being executed.)
> RLF
> "LC" <LC@.discussions.microsoft.com> wrote in message
> news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
>
>|||LC
Dbcc inputbuffer shows the last command to execute through the connection.
Fn_get_sql only can work for a statement that is running _right_now_, since
as soon as a statement is complete the handle returns to 0. Therefore, most
of your sql handles should be zero, but not is a stored procedure is
actually running at the moment.
FWIW - RLF
"LC" <LC@.discussions.microsoft.com> wrote in message
news:6D105C91-1A27-413A-8117-6619CDDE76C4@.microsoft.com...[vbcol=seagreen]
> I've tried that function, but all of the sql handles in my databases are
> 0x000000... Since all of the sql handles are the same (all zero's), I'm
> not
> getting any useful information.
> "Russell Fields" wrote:
>
I'm trying to capture blocking information on my SQL Server 2k box and
running dbcc inputbuffer only shows me the "sp_executesql" command, it
doesn't show me the parameters which is the actual sql. Profiler seems to
have no problem showing the parameters b/c it always shows me the sql that's
running, not the sp_executesql command. Is there some other command that
will pull the sql from a parameterized query a la Profiler? Thanks for any
help here.
lcLC,
Have you tried using fn_get_sql()? (Although for sp_executesql I usually
get nothing unless a stored procedure is being executed.)
RLF
"LC" <LC@.discussions.microsoft.com> wrote in message
news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
> Hi,
> I'm trying to capture blocking information on my SQL Server 2k box and
> running dbcc inputbuffer only shows me the "sp_executesql" command, it
> doesn't show me the parameters which is the actual sql. Profiler seems to
> have no problem showing the parameters b/c it always shows me the sql
> that's
> running, not the sp_executesql command. Is there some other command that
> will pull the sql from a parameterized query a la Profiler? Thanks for
> any
> help here.
> lc|||I've tried that function, but all of the sql handles in my databases are
0x000000... Since all of the sql handles are the same (all zero's), I'm not
getting any useful information.
"Russell Fields" wrote:
> LC,
> Have you tried using fn_get_sql()? (Although for sp_executesql I usually
> get nothing unless a stored procedure is being executed.)
> RLF
> "LC" <LC@.discussions.microsoft.com> wrote in message
> news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
>
>|||LC
Dbcc inputbuffer shows the last command to execute through the connection.
Fn_get_sql only can work for a statement that is running _right_now_, since
as soon as a statement is complete the handle returns to 0. Therefore, most
of your sql handles should be zero, but not is a stored procedure is
actually running at the moment.
FWIW - RLF
"LC" <LC@.discussions.microsoft.com> wrote in message
news:6D105C91-1A27-413A-8117-6619CDDE76C4@.microsoft.com...[vbcol=seagreen]
> I've tried that function, but all of the sql handles in my databases are
> 0x000000... Since all of the sql handles are the same (all zero's), I'm
> not
> getting any useful information.
> "Russell Fields" wrote:
>
Labels:
andrunning,
blocking,
box,
capture,
command,
database,
dbcc,
inputbuffer,
microsoft,
mysql,
oracle,
parameterized,
queries,
server,
sp_executesql,
sql
can dbcc inputbuffer show parameterized queries?
Hi,
I'm trying to capture blocking information on my SQL Server 2k box and
running dbcc inputbuffer only shows me the "sp_executesql" command, it
doesn't show me the parameters which is the actual sql. Profiler seems to
have no problem showing the parameters b/c it always shows me the sql that's
running, not the sp_executesql command. Is there some other command that
will pull the sql from a parameterized query a la Profiler? Thanks for any
help here.
lcLC,
Have you tried using fn_get_sql()? (Although for sp_executesql I usually
get nothing unless a stored procedure is being executed.)
RLF
"LC" <LC@.discussions.microsoft.com> wrote in message
news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
> Hi,
> I'm trying to capture blocking information on my SQL Server 2k box and
> running dbcc inputbuffer only shows me the "sp_executesql" command, it
> doesn't show me the parameters which is the actual sql. Profiler seems to
> have no problem showing the parameters b/c it always shows me the sql
> that's
> running, not the sp_executesql command. Is there some other command that
> will pull the sql from a parameterized query a la Profiler? Thanks for
> any
> help here.
> lc|||I've tried that function, but all of the sql handles in my databases are
0x000000... Since all of the sql handles are the same (all zero's), I'm not
getting any useful information.
"Russell Fields" wrote:
> LC,
> Have you tried using fn_get_sql()? (Although for sp_executesql I usually
> get nothing unless a stored procedure is being executed.)
> RLF
> "LC" <LC@.discussions.microsoft.com> wrote in message
> news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
> > Hi,
> > I'm trying to capture blocking information on my SQL Server 2k box and
> > running dbcc inputbuffer only shows me the "sp_executesql" command, it
> > doesn't show me the parameters which is the actual sql. Profiler seems to
> > have no problem showing the parameters b/c it always shows me the sql
> > that's
> > running, not the sp_executesql command. Is there some other command that
> > will pull the sql from a parameterized query a la Profiler? Thanks for
> > any
> > help here.
> >
> > lc
>
>|||LC
Dbcc inputbuffer shows the last command to execute through the connection.
Fn_get_sql only can work for a statement that is running _right_now_, since
as soon as a statement is complete the handle returns to 0. Therefore, most
of your sql handles should be zero, but not is a stored procedure is
actually running at the moment.
FWIW - RLF
"LC" <LC@.discussions.microsoft.com> wrote in message
news:6D105C91-1A27-413A-8117-6619CDDE76C4@.microsoft.com...
> I've tried that function, but all of the sql handles in my databases are
> 0x000000... Since all of the sql handles are the same (all zero's), I'm
> not
> getting any useful information.
> "Russell Fields" wrote:
>> LC,
>> Have you tried using fn_get_sql()? (Although for sp_executesql I usually
>> get nothing unless a stored procedure is being executed.)
>> RLF
>> "LC" <LC@.discussions.microsoft.com> wrote in message
>> news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
>> > Hi,
>> > I'm trying to capture blocking information on my SQL Server 2k box and
>> > running dbcc inputbuffer only shows me the "sp_executesql" command, it
>> > doesn't show me the parameters which is the actual sql. Profiler seems
>> > to
>> > have no problem showing the parameters b/c it always shows me the sql
>> > that's
>> > running, not the sp_executesql command. Is there some other command
>> > that
>> > will pull the sql from a parameterized query a la Profiler? Thanks for
>> > any
>> > help here.
>> >
>> > lc
>>
>>
I'm trying to capture blocking information on my SQL Server 2k box and
running dbcc inputbuffer only shows me the "sp_executesql" command, it
doesn't show me the parameters which is the actual sql. Profiler seems to
have no problem showing the parameters b/c it always shows me the sql that's
running, not the sp_executesql command. Is there some other command that
will pull the sql from a parameterized query a la Profiler? Thanks for any
help here.
lcLC,
Have you tried using fn_get_sql()? (Although for sp_executesql I usually
get nothing unless a stored procedure is being executed.)
RLF
"LC" <LC@.discussions.microsoft.com> wrote in message
news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
> Hi,
> I'm trying to capture blocking information on my SQL Server 2k box and
> running dbcc inputbuffer only shows me the "sp_executesql" command, it
> doesn't show me the parameters which is the actual sql. Profiler seems to
> have no problem showing the parameters b/c it always shows me the sql
> that's
> running, not the sp_executesql command. Is there some other command that
> will pull the sql from a parameterized query a la Profiler? Thanks for
> any
> help here.
> lc|||I've tried that function, but all of the sql handles in my databases are
0x000000... Since all of the sql handles are the same (all zero's), I'm not
getting any useful information.
"Russell Fields" wrote:
> LC,
> Have you tried using fn_get_sql()? (Although for sp_executesql I usually
> get nothing unless a stored procedure is being executed.)
> RLF
> "LC" <LC@.discussions.microsoft.com> wrote in message
> news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
> > Hi,
> > I'm trying to capture blocking information on my SQL Server 2k box and
> > running dbcc inputbuffer only shows me the "sp_executesql" command, it
> > doesn't show me the parameters which is the actual sql. Profiler seems to
> > have no problem showing the parameters b/c it always shows me the sql
> > that's
> > running, not the sp_executesql command. Is there some other command that
> > will pull the sql from a parameterized query a la Profiler? Thanks for
> > any
> > help here.
> >
> > lc
>
>|||LC
Dbcc inputbuffer shows the last command to execute through the connection.
Fn_get_sql only can work for a statement that is running _right_now_, since
as soon as a statement is complete the handle returns to 0. Therefore, most
of your sql handles should be zero, but not is a stored procedure is
actually running at the moment.
FWIW - RLF
"LC" <LC@.discussions.microsoft.com> wrote in message
news:6D105C91-1A27-413A-8117-6619CDDE76C4@.microsoft.com...
> I've tried that function, but all of the sql handles in my databases are
> 0x000000... Since all of the sql handles are the same (all zero's), I'm
> not
> getting any useful information.
> "Russell Fields" wrote:
>> LC,
>> Have you tried using fn_get_sql()? (Although for sp_executesql I usually
>> get nothing unless a stored procedure is being executed.)
>> RLF
>> "LC" <LC@.discussions.microsoft.com> wrote in message
>> news:013B24CA-D81B-48AA-9D7C-56ABA375A30D@.microsoft.com...
>> > Hi,
>> > I'm trying to capture blocking information on my SQL Server 2k box and
>> > running dbcc inputbuffer only shows me the "sp_executesql" command, it
>> > doesn't show me the parameters which is the actual sql. Profiler seems
>> > to
>> > have no problem showing the parameters b/c it always shows me the sql
>> > that's
>> > running, not the sp_executesql command. Is there some other command
>> > that
>> > will pull the sql from a parameterized query a la Profiler? Thanks for
>> > any
>> > help here.
>> >
>> > lc
>>
>>
can dbcc indexdefrag reindex the whole database in one time?
Hi,
Normally i run the DBCC INDEXDEFRAG one table in one time, can run
all the tables in one time?
--
Thank you very much!
Best regards,
FlorenceHi,
This gives DBCC DBREINDEX. You can use this during off-peak hrs, as this is
not an online re-indexing operation. If you still want to use DBCC
INDEXDEFRAG, look at the usage of the same in BOL, and replace it with DBCC
DBREINDEX in given script.
/* Re-indexes the specified database */
CREATE PROCEDURE scr_defrag_database
@.dbname nvarchar(256)
AS
BEGIN
-- Quote the database name with brackets
DECLARE @.quoteddbname nvarchar(256)
SET @.quoteddbname = quotename( @.dbname )
-- The outer EXEC is so we can do USE, not allowed in stored procs
-- The inner EXEC does the actual reindex on each table in the
-- specified database
EXEC('
USE '+ @.quoteddbname +'
DECLARE @.stablename sysname
DECLARE PKMS_Tables CURSOR LOCAL FOR
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = ''BASE TABLE'' ORDER BY 1
OPEN PKMS_Tables
FETCH NEXT FROM PKMS_Tables INTO @.stablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.stablename = quotename(@.stablename, ''[]'')
EXEC('' DBCC DBREINDEX ( ''+@.stablename+'') WITH NO_INFOMSGS'')
FETCH NEXT FROM PKMS_Tables INTO @.stablename
END
CLOSE PKMS_Tables')
END
--
Thanks
Yogish|||CREATE PROC ukug2_op_defrag
@.is_reindex char(1) = 'Y'
AS
BEGIN
SET NOCOUNT ON
-- Basis of script taken from BOL
CREATE TABLE #fraglist (
ObjectName CHAR (255),
ObjectId INT,
IndexName CHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
DECLARE tables_cur CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_NAME
OPEN tables_cur
DECLARE @.ObjectName sysname
FETCH NEXT FROM tables_cur INTO @.ObjectName
WHILE @.@.FETCH_STATUS = 0
BEGIN
EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH COUNT_ROWS,
NO_INFOMSGS' )
INSERT #fraglist
EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
FETCH NEXT FROM tables_cur INTO @.ObjectName
END
CLOSE tables_cur
DEALLOCATE tables_cur
SELECT *
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then don't do
anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
IF @.is_reindex = 'Y'
BEGIN
DECLARE defrag_cur CURSOR FOR
SELECT ObjectName,
IndexName
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then
don't do anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
DECLARE @.IndexName sysname
DECLARE @.sql varchar(1000)
OPEN defrag_cur
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
WHILE @.@.FETCH_STATUS = 0
BEGIN
PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
indexname=' + @.IndexName
SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
+ @.IndexName + ')'
PRINT @.sql
EXEC( @.sql )
PRINT 'Complete.'
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
END
DEALLOCATE defrag_cur
END
DROP TABLE #fraglist
END
Tony Rogerson
SQL Server MVP
http://www.sqlserverfaq.com?mbr=21
(Create your own groups, Forum, FAQ's and a ton more)|||This is a very timely thread for me as I'm just getting ready to implement a
SP that is based on the BOL sp.
I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created from
the BOL base is a bit different and I guess I just want to know if the one
if BOL is incorrect or just different.
It determines the indexes to defrag based on the results of:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
if you wanted to exclude clustered indexes I suppose you would be able to
modify to:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
FROM jdit_fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
Thanks
Ivan
"Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
> CREATE PROC ukug2_op_defrag
> @.is_reindex char(1) = 'Y'
> AS
> BEGIN
> SET NOCOUNT ON
> -- Basis of script taken from BOL
> CREATE TABLE #fraglist (
> ObjectName CHAR (255),
> ObjectId INT,
> IndexName CHAR (255),
> IndexId INT,
> Lvl INT,
> CountPages INT,
> CountRows INT,
> MinRecSize INT,
> MaxRecSize INT,
> AvgRecSize INT,
> ForRecCount INT,
> Extents INT,
> ExtentSwitches INT,
> AvgFreeBytes INT,
> AvgPageDensity INT,
> ScanDensity DECIMAL,
> BestCount INT,
> ActualCount INT,
> LogicalFrag DECIMAL,
> ExtentFrag DECIMAL)
> DECLARE tables_cur CURSOR FOR
> SELECT TABLE_NAME
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'BASE TABLE'
> ORDER BY TABLE_NAME
> OPEN tables_cur
> DECLARE @.ObjectName sysname
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
> COUNT_ROWS, NO_INFOMSGS' )
> INSERT #fraglist
> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> END
> CLOSE tables_cur
> DEALLOCATE tables_cur
> SELECT *
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then don't do
> anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> IF @.is_reindex = 'Y'
> BEGIN
> DECLARE defrag_cur CURSOR FOR
> SELECT ObjectName,
> IndexName
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then
> don't do anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> DECLARE @.IndexName sysname
> DECLARE @.sql varchar(1000)
> OPEN defrag_cur
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
> indexname=' + @.IndexName
> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
> + @.IndexName + ')'
> PRINT @.sql
> EXEC( @.sql )
> PRINT 'Complete.'
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> END
> DEALLOCATE defrag_cur
> END
> DROP TABLE #fraglist
> END
>
> --
> Tony Rogerson
> SQL Server MVP
> http://www.sqlserverfaq.com?mbr=21
> (Create your own groups, Forum, FAQ's and a ton more)
>|||Boy, I wish I could recall messages...I think I answered my own
question--this is for DBREINDEX, not INDEXDEFRAG.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
> This is a very timely thread for me as I'm just getting ready to implement
> a SP that is based on the BOL sp.
> I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
> DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created
> from the BOL base is a bit different and I guess I just want to know if
> the one if BOL is incorrect or just different.
> It determines the indexes to defrag based on the results of:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> FROM #fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> if you wanted to exclude clustered indexes I suppose you would be able to
> modify to:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
> FROM jdit_fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
> Thanks
> Ivan
> "Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
> news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
>> CREATE PROC ukug2_op_defrag
>> @.is_reindex char(1) = 'Y'
>> AS
>> BEGIN
>> SET NOCOUNT ON
>> -- Basis of script taken from BOL
>> CREATE TABLE #fraglist (
>> ObjectName CHAR (255),
>> ObjectId INT,
>> IndexName CHAR (255),
>> IndexId INT,
>> Lvl INT,
>> CountPages INT,
>> CountRows INT,
>> MinRecSize INT,
>> MaxRecSize INT,
>> AvgRecSize INT,
>> ForRecCount INT,
>> Extents INT,
>> ExtentSwitches INT,
>> AvgFreeBytes INT,
>> AvgPageDensity INT,
>> ScanDensity DECIMAL,
>> BestCount INT,
>> ActualCount INT,
>> LogicalFrag DECIMAL,
>> ExtentFrag DECIMAL)
>> DECLARE tables_cur CURSOR FOR
>> SELECT TABLE_NAME
>> FROM INFORMATION_SCHEMA.TABLES
>> WHERE TABLE_TYPE = 'BASE TABLE'
>> ORDER BY TABLE_NAME
>> OPEN tables_cur
>> DECLARE @.ObjectName sysname
>> FETCH NEXT FROM tables_cur INTO @.ObjectName
>> WHILE @.@.FETCH_STATUS = 0
>> BEGIN
>> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
>> COUNT_ROWS, NO_INFOMSGS' )
>> INSERT #fraglist
>> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
>> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
>> FETCH NEXT FROM tables_cur INTO @.ObjectName
>> END
>> CLOSE tables_cur
>> DEALLOCATE tables_cur
>> SELECT *
>> FROM #fraglist fo
>> WHERE LogicalFrag > 30 -- % fragmentation
>> AND IndexID BETWEEN 1 AND 254
>> AND ( IndexID = 1
>> OR NOT EXISTS (
>> SELECT * -- If clustered index to defrag then don't do
>> anything else (no point).
>> FROM #fraglist fi
>> WHERE fi.ObjectId = fo.ObjectId
>> AND fi.IndexID = 1
>> )
>> )
>> IF @.is_reindex = 'Y'
>> BEGIN
>> DECLARE defrag_cur CURSOR FOR
>> SELECT ObjectName,
>> IndexName
>> FROM #fraglist fo
>> WHERE LogicalFrag > 30 -- % fragmentation
>> AND IndexID BETWEEN 1 AND 254
>> AND ( IndexID = 1
>> OR NOT EXISTS (
>> SELECT * -- If clustered index to defrag then
>> don't do anything else (no point).
>> FROM #fraglist fi
>> WHERE fi.ObjectId = fo.ObjectId
>> AND fi.IndexID = 1
>> )
>> )
>> DECLARE @.IndexName sysname
>> DECLARE @.sql varchar(1000)
>> OPEN defrag_cur
>> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
>> WHILE @.@.FETCH_STATUS = 0
>> BEGIN
>> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
>> indexname=' + @.IndexName
>> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''',
>> ' + @.IndexName + ')'
>> PRINT @.sql
>> EXEC( @.sql )
>> PRINT 'Complete.'
>> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
>> END
>> DEALLOCATE defrag_cur
>> END
>> DROP TABLE #fraglist
>> END
>>
>> --
>> Tony Rogerson
>> SQL Server MVP
>> http://www.sqlserverfaq.com?mbr=21
>> (Create your own groups, Forum, FAQ's and a ton more)
>>
>|||Seems like a bit of confusion here. DBCC INDEXDEFRAG can defragment
clustered and non-clustered indexes. DBCC DBREINDEX can rebuild clustered
and non-clustered indexes. The example scripts in this thread are taken from
Example E in BOL for DBCC SHOWCONTIG - look there for more details.
You should read the whitepaper below on fragmentation and when you actually
need to do anything about it (don't just blindly defrag/rebuild everything
in your database - you're wasting resources).
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
Regards.
--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:O3CQZhB9EHA.1228@.tk2msftngp13.phx.gbl...
> Boy, I wish I could recall messages...I think I answered my own
> question--this is for DBREINDEX, not INDEXDEFRAG.
> "Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
> news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
> > This is a very timely thread for me as I'm just getting ready to
implement
> > a SP that is based on the BOL sp.
> >
> > I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
> > DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created
> > from the BOL base is a bit different and I guess I just want to know if
> > the one if BOL is incorrect or just different.
> >
> > It determines the indexes to defrag based on the results of:
> >
> > SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> > FROM #fraglist
> > WHERE LogicalFrag >= @.maxfrag
> > AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> >
> > if you wanted to exclude clustered indexes I suppose you would be able
to
> > modify to:
> >
> > SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
> > FROM jdit_fraglist
> > WHERE LogicalFrag >= @.maxfrag
> > AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> > AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
> >
> > Thanks
> >
> > Ivan
> >
> > "Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
> > news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
> >> CREATE PROC ukug2_op_defrag
> >> @.is_reindex char(1) = 'Y'
> >> AS
> >> BEGIN
> >> SET NOCOUNT ON
> >>
> >> -- Basis of script taken from BOL
> >>
> >> CREATE TABLE #fraglist (
> >> ObjectName CHAR (255),
> >> ObjectId INT,
> >> IndexName CHAR (255),
> >> IndexId INT,
> >> Lvl INT,
> >> CountPages INT,
> >> CountRows INT,
> >> MinRecSize INT,
> >> MaxRecSize INT,
> >> AvgRecSize INT,
> >> ForRecCount INT,
> >> Extents INT,
> >> ExtentSwitches INT,
> >> AvgFreeBytes INT,
> >> AvgPageDensity INT,
> >> ScanDensity DECIMAL,
> >> BestCount INT,
> >> ActualCount INT,
> >> LogicalFrag DECIMAL,
> >> ExtentFrag DECIMAL)
> >>
> >> DECLARE tables_cur CURSOR FOR
> >> SELECT TABLE_NAME
> >> FROM INFORMATION_SCHEMA.TABLES
> >> WHERE TABLE_TYPE = 'BASE TABLE'
> >> ORDER BY TABLE_NAME
> >>
> >> OPEN tables_cur
> >>
> >> DECLARE @.ObjectName sysname
> >>
> >> FETCH NEXT FROM tables_cur INTO @.ObjectName
> >>
> >> WHILE @.@.FETCH_STATUS = 0
> >> BEGIN
> >> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
> >> COUNT_ROWS, NO_INFOMSGS' )
> >>
> >> INSERT #fraglist
> >> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
> >> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
> >>
> >> FETCH NEXT FROM tables_cur INTO @.ObjectName
> >>
> >> END
> >>
> >> CLOSE tables_cur
> >> DEALLOCATE tables_cur
> >>
> >> SELECT *
> >> FROM #fraglist fo
> >> WHERE LogicalFrag > 30 -- % fragmentation
> >> AND IndexID BETWEEN 1 AND 254
> >> AND ( IndexID = 1
> >> OR NOT EXISTS (
> >> SELECT * -- If clustered index to defrag then don't
do
> >> anything else (no point).
> >> FROM #fraglist fi
> >> WHERE fi.ObjectId = fo.ObjectId
> >> AND fi.IndexID = 1
> >> )
> >> )
> >>
> >> IF @.is_reindex = 'Y'
> >> BEGIN
> >> DECLARE defrag_cur CURSOR FOR
> >> SELECT ObjectName,
> >> IndexName
> >> FROM #fraglist fo
> >> WHERE LogicalFrag > 30 -- % fragmentation
> >> AND IndexID BETWEEN 1 AND 254
> >> AND ( IndexID = 1
> >> OR NOT EXISTS (
> >> SELECT * -- If clustered index to defrag then
> >> don't do anything else (no point).
> >> FROM #fraglist fi
> >> WHERE fi.ObjectId = fo.ObjectId
> >> AND fi.IndexID = 1
> >> )
> >> )
> >>
> >> DECLARE @.IndexName sysname
> >> DECLARE @.sql varchar(1000)
> >>
> >> OPEN defrag_cur
> >>
> >> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> >>
> >> WHILE @.@.FETCH_STATUS = 0
> >> BEGIN
> >> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
> >> indexname=' + @.IndexName
> >> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) +
''',
> >> ' + @.IndexName + ')'
> >> PRINT @.sql
> >> EXEC( @.sql )
> >> PRINT 'Complete.'
> >>
> >> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> >>
> >> END
> >> DEALLOCATE defrag_cur
> >> END
> >>
> >> DROP TABLE #fraglist
> >>
> >> END
> >>
> >>
> >> --
> >> Tony Rogerson
> >> SQL Server MVP
> >> http://www.sqlserverfaq.com?mbr=21
> >> (Create your own groups, Forum, FAQ's and a ton more)
> >>
> >>
> >
> >
>
Normally i run the DBCC INDEXDEFRAG one table in one time, can run
all the tables in one time?
--
Thank you very much!
Best regards,
FlorenceHi,
This gives DBCC DBREINDEX. You can use this during off-peak hrs, as this is
not an online re-indexing operation. If you still want to use DBCC
INDEXDEFRAG, look at the usage of the same in BOL, and replace it with DBCC
DBREINDEX in given script.
/* Re-indexes the specified database */
CREATE PROCEDURE scr_defrag_database
@.dbname nvarchar(256)
AS
BEGIN
-- Quote the database name with brackets
DECLARE @.quoteddbname nvarchar(256)
SET @.quoteddbname = quotename( @.dbname )
-- The outer EXEC is so we can do USE, not allowed in stored procs
-- The inner EXEC does the actual reindex on each table in the
-- specified database
EXEC('
USE '+ @.quoteddbname +'
DECLARE @.stablename sysname
DECLARE PKMS_Tables CURSOR LOCAL FOR
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = ''BASE TABLE'' ORDER BY 1
OPEN PKMS_Tables
FETCH NEXT FROM PKMS_Tables INTO @.stablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.stablename = quotename(@.stablename, ''[]'')
EXEC('' DBCC DBREINDEX ( ''+@.stablename+'') WITH NO_INFOMSGS'')
FETCH NEXT FROM PKMS_Tables INTO @.stablename
END
CLOSE PKMS_Tables')
END
--
Thanks
Yogish|||CREATE PROC ukug2_op_defrag
@.is_reindex char(1) = 'Y'
AS
BEGIN
SET NOCOUNT ON
-- Basis of script taken from BOL
CREATE TABLE #fraglist (
ObjectName CHAR (255),
ObjectId INT,
IndexName CHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
DECLARE tables_cur CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_NAME
OPEN tables_cur
DECLARE @.ObjectName sysname
FETCH NEXT FROM tables_cur INTO @.ObjectName
WHILE @.@.FETCH_STATUS = 0
BEGIN
EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH COUNT_ROWS,
NO_INFOMSGS' )
INSERT #fraglist
EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
FETCH NEXT FROM tables_cur INTO @.ObjectName
END
CLOSE tables_cur
DEALLOCATE tables_cur
SELECT *
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then don't do
anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
IF @.is_reindex = 'Y'
BEGIN
DECLARE defrag_cur CURSOR FOR
SELECT ObjectName,
IndexName
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then
don't do anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
DECLARE @.IndexName sysname
DECLARE @.sql varchar(1000)
OPEN defrag_cur
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
WHILE @.@.FETCH_STATUS = 0
BEGIN
PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
indexname=' + @.IndexName
SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
+ @.IndexName + ')'
PRINT @.sql
EXEC( @.sql )
PRINT 'Complete.'
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
END
DEALLOCATE defrag_cur
END
DROP TABLE #fraglist
END
Tony Rogerson
SQL Server MVP
http://www.sqlserverfaq.com?mbr=21
(Create your own groups, Forum, FAQ's and a ton more)|||This is a very timely thread for me as I'm just getting ready to implement a
SP that is based on the BOL sp.
I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created from
the BOL base is a bit different and I guess I just want to know if the one
if BOL is incorrect or just different.
It determines the indexes to defrag based on the results of:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
if you wanted to exclude clustered indexes I suppose you would be able to
modify to:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
FROM jdit_fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
Thanks
Ivan
"Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
> CREATE PROC ukug2_op_defrag
> @.is_reindex char(1) = 'Y'
> AS
> BEGIN
> SET NOCOUNT ON
> -- Basis of script taken from BOL
> CREATE TABLE #fraglist (
> ObjectName CHAR (255),
> ObjectId INT,
> IndexName CHAR (255),
> IndexId INT,
> Lvl INT,
> CountPages INT,
> CountRows INT,
> MinRecSize INT,
> MaxRecSize INT,
> AvgRecSize INT,
> ForRecCount INT,
> Extents INT,
> ExtentSwitches INT,
> AvgFreeBytes INT,
> AvgPageDensity INT,
> ScanDensity DECIMAL,
> BestCount INT,
> ActualCount INT,
> LogicalFrag DECIMAL,
> ExtentFrag DECIMAL)
> DECLARE tables_cur CURSOR FOR
> SELECT TABLE_NAME
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'BASE TABLE'
> ORDER BY TABLE_NAME
> OPEN tables_cur
> DECLARE @.ObjectName sysname
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
> COUNT_ROWS, NO_INFOMSGS' )
> INSERT #fraglist
> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> END
> CLOSE tables_cur
> DEALLOCATE tables_cur
> SELECT *
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then don't do
> anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> IF @.is_reindex = 'Y'
> BEGIN
> DECLARE defrag_cur CURSOR FOR
> SELECT ObjectName,
> IndexName
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then
> don't do anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> DECLARE @.IndexName sysname
> DECLARE @.sql varchar(1000)
> OPEN defrag_cur
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
> indexname=' + @.IndexName
> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
> + @.IndexName + ')'
> PRINT @.sql
> EXEC( @.sql )
> PRINT 'Complete.'
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> END
> DEALLOCATE defrag_cur
> END
> DROP TABLE #fraglist
> END
>
> --
> Tony Rogerson
> SQL Server MVP
> http://www.sqlserverfaq.com?mbr=21
> (Create your own groups, Forum, FAQ's and a ton more)
>|||Boy, I wish I could recall messages...I think I answered my own
question--this is for DBREINDEX, not INDEXDEFRAG.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
> This is a very timely thread for me as I'm just getting ready to implement
> a SP that is based on the BOL sp.
> I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
> DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created
> from the BOL base is a bit different and I guess I just want to know if
> the one if BOL is incorrect or just different.
> It determines the indexes to defrag based on the results of:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> FROM #fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> if you wanted to exclude clustered indexes I suppose you would be able to
> modify to:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
> FROM jdit_fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
> Thanks
> Ivan
> "Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
> news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
>> CREATE PROC ukug2_op_defrag
>> @.is_reindex char(1) = 'Y'
>> AS
>> BEGIN
>> SET NOCOUNT ON
>> -- Basis of script taken from BOL
>> CREATE TABLE #fraglist (
>> ObjectName CHAR (255),
>> ObjectId INT,
>> IndexName CHAR (255),
>> IndexId INT,
>> Lvl INT,
>> CountPages INT,
>> CountRows INT,
>> MinRecSize INT,
>> MaxRecSize INT,
>> AvgRecSize INT,
>> ForRecCount INT,
>> Extents INT,
>> ExtentSwitches INT,
>> AvgFreeBytes INT,
>> AvgPageDensity INT,
>> ScanDensity DECIMAL,
>> BestCount INT,
>> ActualCount INT,
>> LogicalFrag DECIMAL,
>> ExtentFrag DECIMAL)
>> DECLARE tables_cur CURSOR FOR
>> SELECT TABLE_NAME
>> FROM INFORMATION_SCHEMA.TABLES
>> WHERE TABLE_TYPE = 'BASE TABLE'
>> ORDER BY TABLE_NAME
>> OPEN tables_cur
>> DECLARE @.ObjectName sysname
>> FETCH NEXT FROM tables_cur INTO @.ObjectName
>> WHILE @.@.FETCH_STATUS = 0
>> BEGIN
>> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
>> COUNT_ROWS, NO_INFOMSGS' )
>> INSERT #fraglist
>> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
>> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
>> FETCH NEXT FROM tables_cur INTO @.ObjectName
>> END
>> CLOSE tables_cur
>> DEALLOCATE tables_cur
>> SELECT *
>> FROM #fraglist fo
>> WHERE LogicalFrag > 30 -- % fragmentation
>> AND IndexID BETWEEN 1 AND 254
>> AND ( IndexID = 1
>> OR NOT EXISTS (
>> SELECT * -- If clustered index to defrag then don't do
>> anything else (no point).
>> FROM #fraglist fi
>> WHERE fi.ObjectId = fo.ObjectId
>> AND fi.IndexID = 1
>> )
>> )
>> IF @.is_reindex = 'Y'
>> BEGIN
>> DECLARE defrag_cur CURSOR FOR
>> SELECT ObjectName,
>> IndexName
>> FROM #fraglist fo
>> WHERE LogicalFrag > 30 -- % fragmentation
>> AND IndexID BETWEEN 1 AND 254
>> AND ( IndexID = 1
>> OR NOT EXISTS (
>> SELECT * -- If clustered index to defrag then
>> don't do anything else (no point).
>> FROM #fraglist fi
>> WHERE fi.ObjectId = fo.ObjectId
>> AND fi.IndexID = 1
>> )
>> )
>> DECLARE @.IndexName sysname
>> DECLARE @.sql varchar(1000)
>> OPEN defrag_cur
>> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
>> WHILE @.@.FETCH_STATUS = 0
>> BEGIN
>> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
>> indexname=' + @.IndexName
>> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''',
>> ' + @.IndexName + ')'
>> PRINT @.sql
>> EXEC( @.sql )
>> PRINT 'Complete.'
>> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
>> END
>> DEALLOCATE defrag_cur
>> END
>> DROP TABLE #fraglist
>> END
>>
>> --
>> Tony Rogerson
>> SQL Server MVP
>> http://www.sqlserverfaq.com?mbr=21
>> (Create your own groups, Forum, FAQ's and a ton more)
>>
>|||Seems like a bit of confusion here. DBCC INDEXDEFRAG can defragment
clustered and non-clustered indexes. DBCC DBREINDEX can rebuild clustered
and non-clustered indexes. The example scripts in this thread are taken from
Example E in BOL for DBCC SHOWCONTIG - look there for more details.
You should read the whitepaper below on fragmentation and when you actually
need to do anything about it (don't just blindly defrag/rebuild everything
in your database - you're wasting resources).
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
Regards.
--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:O3CQZhB9EHA.1228@.tk2msftngp13.phx.gbl...
> Boy, I wish I could recall messages...I think I answered my own
> question--this is for DBREINDEX, not INDEXDEFRAG.
> "Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
> news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
> > This is a very timely thread for me as I'm just getting ready to
implement
> > a SP that is based on the BOL sp.
> >
> > I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
> > DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created
> > from the BOL base is a bit different and I guess I just want to know if
> > the one if BOL is incorrect or just different.
> >
> > It determines the indexes to defrag based on the results of:
> >
> > SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> > FROM #fraglist
> > WHERE LogicalFrag >= @.maxfrag
> > AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> >
> > if you wanted to exclude clustered indexes I suppose you would be able
to
> > modify to:
> >
> > SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
> > FROM jdit_fraglist
> > WHERE LogicalFrag >= @.maxfrag
> > AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> > AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
> >
> > Thanks
> >
> > Ivan
> >
> > "Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
> > news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
> >> CREATE PROC ukug2_op_defrag
> >> @.is_reindex char(1) = 'Y'
> >> AS
> >> BEGIN
> >> SET NOCOUNT ON
> >>
> >> -- Basis of script taken from BOL
> >>
> >> CREATE TABLE #fraglist (
> >> ObjectName CHAR (255),
> >> ObjectId INT,
> >> IndexName CHAR (255),
> >> IndexId INT,
> >> Lvl INT,
> >> CountPages INT,
> >> CountRows INT,
> >> MinRecSize INT,
> >> MaxRecSize INT,
> >> AvgRecSize INT,
> >> ForRecCount INT,
> >> Extents INT,
> >> ExtentSwitches INT,
> >> AvgFreeBytes INT,
> >> AvgPageDensity INT,
> >> ScanDensity DECIMAL,
> >> BestCount INT,
> >> ActualCount INT,
> >> LogicalFrag DECIMAL,
> >> ExtentFrag DECIMAL)
> >>
> >> DECLARE tables_cur CURSOR FOR
> >> SELECT TABLE_NAME
> >> FROM INFORMATION_SCHEMA.TABLES
> >> WHERE TABLE_TYPE = 'BASE TABLE'
> >> ORDER BY TABLE_NAME
> >>
> >> OPEN tables_cur
> >>
> >> DECLARE @.ObjectName sysname
> >>
> >> FETCH NEXT FROM tables_cur INTO @.ObjectName
> >>
> >> WHILE @.@.FETCH_STATUS = 0
> >> BEGIN
> >> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
> >> COUNT_ROWS, NO_INFOMSGS' )
> >>
> >> INSERT #fraglist
> >> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
> >> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
> >>
> >> FETCH NEXT FROM tables_cur INTO @.ObjectName
> >>
> >> END
> >>
> >> CLOSE tables_cur
> >> DEALLOCATE tables_cur
> >>
> >> SELECT *
> >> FROM #fraglist fo
> >> WHERE LogicalFrag > 30 -- % fragmentation
> >> AND IndexID BETWEEN 1 AND 254
> >> AND ( IndexID = 1
> >> OR NOT EXISTS (
> >> SELECT * -- If clustered index to defrag then don't
do
> >> anything else (no point).
> >> FROM #fraglist fi
> >> WHERE fi.ObjectId = fo.ObjectId
> >> AND fi.IndexID = 1
> >> )
> >> )
> >>
> >> IF @.is_reindex = 'Y'
> >> BEGIN
> >> DECLARE defrag_cur CURSOR FOR
> >> SELECT ObjectName,
> >> IndexName
> >> FROM #fraglist fo
> >> WHERE LogicalFrag > 30 -- % fragmentation
> >> AND IndexID BETWEEN 1 AND 254
> >> AND ( IndexID = 1
> >> OR NOT EXISTS (
> >> SELECT * -- If clustered index to defrag then
> >> don't do anything else (no point).
> >> FROM #fraglist fi
> >> WHERE fi.ObjectId = fo.ObjectId
> >> AND fi.IndexID = 1
> >> )
> >> )
> >>
> >> DECLARE @.IndexName sysname
> >> DECLARE @.sql varchar(1000)
> >>
> >> OPEN defrag_cur
> >>
> >> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> >>
> >> WHILE @.@.FETCH_STATUS = 0
> >> BEGIN
> >> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
> >> indexname=' + @.IndexName
> >> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) +
''',
> >> ' + @.IndexName + ')'
> >> PRINT @.sql
> >> EXEC( @.sql )
> >> PRINT 'Complete.'
> >>
> >> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> >>
> >> END
> >> DEALLOCATE defrag_cur
> >> END
> >>
> >> DROP TABLE #fraglist
> >>
> >> END
> >>
> >>
> >> --
> >> Tony Rogerson
> >> SQL Server MVP
> >> http://www.sqlserverfaq.com?mbr=21
> >> (Create your own groups, Forum, FAQ's and a ton more)
> >>
> >>
> >
> >
>
can dbcc indexdefrag reindex the whole database in one time?
Hi,
Normally i run the DBCC INDEXDEFRAG one table in one time, can run
all the tables in one time?
Thank you very much!
Best regards,
Florence
Hi,
This gives DBCC DBREINDEX. You can use this during off-peak hrs, as this is
not an online re-indexing operation. If you still want to use DBCC
INDEXDEFRAG, look at the usage of the same in BOL, and replace it with DBCC
DBREINDEX in given script.
/* Re-indexes the specified database */
CREATE PROCEDURE scr_defrag_database
@.dbname nvarchar(256)
AS
BEGIN
-- Quote the database name with brackets
DECLARE @.quoteddbname nvarchar(256)
SET @.quoteddbname = quotename( @.dbname )
-- The outer EXEC is so we can do USE, not allowed in stored procs
-- The inner EXEC does the actual reindex on each table in the
-- specified database
EXEC('
USE '+ @.quoteddbname +'
DECLARE @.stablename sysname
DECLARE PKMS_Tables CURSOR LOCAL FOR
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = ''BASE TABLE'' ORDER BY 1
OPEN PKMS_Tables
FETCH NEXT FROM PKMS_Tables INTO @.stablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.stablename = quotename(@.stablename, ''[]'')
EXEC('' DBCC DBREINDEX ( ''+@.stablename+'') WITH NO_INFOMSGS'')
FETCH NEXT FROM PKMS_Tables INTO @.stablename
END
CLOSE PKMS_Tables')
END
Thanks
Yogish
|||CREATE PROC ukug2_op_defrag
@.is_reindex char(1) = 'Y'
AS
BEGIN
SET NOCOUNT ON
-- Basis of script taken from BOL
CREATE TABLE #fraglist (
ObjectName CHAR (255),
ObjectId INT,
IndexName CHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
DECLARE tables_cur CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_NAME
OPEN tables_cur
DECLARE @.ObjectName sysname
FETCH NEXT FROM tables_cur INTO @.ObjectName
WHILE @.@.FETCH_STATUS = 0
BEGIN
EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH COUNT_ROWS,
NO_INFOMSGS' )
INSERT #fraglist
EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
FETCH NEXT FROM tables_cur INTO @.ObjectName
END
CLOSE tables_cur
DEALLOCATE tables_cur
SELECT *
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then don't do
anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
IF @.is_reindex = 'Y'
BEGIN
DECLARE defrag_cur CURSOR FOR
SELECT ObjectName,
IndexName
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then
don't do anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
DECLARE @.IndexName sysname
DECLARE @.sql varchar(1000)
OPEN defrag_cur
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
WHILE @.@.FETCH_STATUS = 0
BEGIN
PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
indexname=' + @.IndexName
SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
+ @.IndexName + ')'
PRINT @.sql
EXEC( @.sql )
PRINT 'Complete.'
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
END
DEALLOCATE defrag_cur
END
DROP TABLE #fraglist
END
Tony Rogerson
SQL Server MVP
http://www.sqlserverfaq.com?mbr=21
(Create your own groups, Forum, FAQ's and a ton more)
|||This is a very timely thread for me as I'm just getting ready to implement a
SP that is based on the BOL sp.
I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created from
the BOL base is a bit different and I guess I just want to know if the one
if BOL is incorrect or just different.
It determines the indexes to defrag based on the results of:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
if you wanted to exclude clustered indexes I suppose you would be able to
modify to:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
FROM jdit_fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
Thanks
Ivan
"Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
> CREATE PROC ukug2_op_defrag
> @.is_reindex char(1) = 'Y'
> AS
> BEGIN
> SET NOCOUNT ON
> -- Basis of script taken from BOL
> CREATE TABLE #fraglist (
> ObjectName CHAR (255),
> ObjectId INT,
> IndexName CHAR (255),
> IndexId INT,
> Lvl INT,
> CountPages INT,
> CountRows INT,
> MinRecSize INT,
> MaxRecSize INT,
> AvgRecSize INT,
> ForRecCount INT,
> Extents INT,
> ExtentSwitches INT,
> AvgFreeBytes INT,
> AvgPageDensity INT,
> ScanDensity DECIMAL,
> BestCount INT,
> ActualCount INT,
> LogicalFrag DECIMAL,
> ExtentFrag DECIMAL)
> DECLARE tables_cur CURSOR FOR
> SELECT TABLE_NAME
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'BASE TABLE'
> ORDER BY TABLE_NAME
> OPEN tables_cur
> DECLARE @.ObjectName sysname
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
> COUNT_ROWS, NO_INFOMSGS' )
> INSERT #fraglist
> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> END
> CLOSE tables_cur
> DEALLOCATE tables_cur
> SELECT *
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then don't do
> anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> IF @.is_reindex = 'Y'
> BEGIN
> DECLARE defrag_cur CURSOR FOR
> SELECT ObjectName,
> IndexName
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then
> don't do anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> DECLARE @.IndexName sysname
> DECLARE @.sql varchar(1000)
> OPEN defrag_cur
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
> indexname=' + @.IndexName
> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
> + @.IndexName + ')'
> PRINT @.sql
> EXEC( @.sql )
> PRINT 'Complete.'
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> END
> DEALLOCATE defrag_cur
> END
> DROP TABLE #fraglist
> END
>
> --
> Tony Rogerson
> SQL Server MVP
> http://www.sqlserverfaq.com?mbr=21
> (Create your own groups, Forum, FAQ's and a ton more)
>
|||Boy, I wish I could recall messages...I think I answered my own
question--this is for DBREINDEX, not INDEXDEFRAG.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
> This is a very timely thread for me as I'm just getting ready to implement
> a SP that is based on the BOL sp.
> I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
> DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created
> from the BOL base is a bit different and I guess I just want to know if
> the one if BOL is incorrect or just different.
> It determines the indexes to defrag based on the results of:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> FROM #fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> if you wanted to exclude clustered indexes I suppose you would be able to
> modify to:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
> FROM jdit_fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
> Thanks
> Ivan
> "Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
> news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
>
|||Seems like a bit of confusion here. DBCC INDEXDEFRAG can defragment
clustered and non-clustered indexes. DBCC DBREINDEX can rebuild clustered
and non-clustered indexes. The example scripts in this thread are taken from
Example E in BOL for DBCC SHOWCONTIG - look there for more details.
You should read the whitepaper below on fragmentation and when you actually
need to do anything about it (don't just blindly defrag/rebuild everything
in your database - you're wasting resources).
http://www.microsoft.com/technet/pro.../ss2kidbp.mspx
Regards.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:O3CQZhB9EHA.1228@.tk2msftngp13.phx.gbl...[vbcol=seagreen]
> Boy, I wish I could recall messages...I think I answered my own
> question--this is for DBREINDEX, not INDEXDEFRAG.
> "Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
> news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
implement[vbcol=seagreen]
to[vbcol=seagreen]
do[vbcol=seagreen]
''',
>
Normally i run the DBCC INDEXDEFRAG one table in one time, can run
all the tables in one time?
Thank you very much!
Best regards,
Florence
Hi,
This gives DBCC DBREINDEX. You can use this during off-peak hrs, as this is
not an online re-indexing operation. If you still want to use DBCC
INDEXDEFRAG, look at the usage of the same in BOL, and replace it with DBCC
DBREINDEX in given script.
/* Re-indexes the specified database */
CREATE PROCEDURE scr_defrag_database
@.dbname nvarchar(256)
AS
BEGIN
-- Quote the database name with brackets
DECLARE @.quoteddbname nvarchar(256)
SET @.quoteddbname = quotename( @.dbname )
-- The outer EXEC is so we can do USE, not allowed in stored procs
-- The inner EXEC does the actual reindex on each table in the
-- specified database
EXEC('
USE '+ @.quoteddbname +'
DECLARE @.stablename sysname
DECLARE PKMS_Tables CURSOR LOCAL FOR
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = ''BASE TABLE'' ORDER BY 1
OPEN PKMS_Tables
FETCH NEXT FROM PKMS_Tables INTO @.stablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.stablename = quotename(@.stablename, ''[]'')
EXEC('' DBCC DBREINDEX ( ''+@.stablename+'') WITH NO_INFOMSGS'')
FETCH NEXT FROM PKMS_Tables INTO @.stablename
END
CLOSE PKMS_Tables')
END
Thanks
Yogish
|||CREATE PROC ukug2_op_defrag
@.is_reindex char(1) = 'Y'
AS
BEGIN
SET NOCOUNT ON
-- Basis of script taken from BOL
CREATE TABLE #fraglist (
ObjectName CHAR (255),
ObjectId INT,
IndexName CHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
DECLARE tables_cur CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_NAME
OPEN tables_cur
DECLARE @.ObjectName sysname
FETCH NEXT FROM tables_cur INTO @.ObjectName
WHILE @.@.FETCH_STATUS = 0
BEGIN
EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH COUNT_ROWS,
NO_INFOMSGS' )
INSERT #fraglist
EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
FETCH NEXT FROM tables_cur INTO @.ObjectName
END
CLOSE tables_cur
DEALLOCATE tables_cur
SELECT *
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then don't do
anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
IF @.is_reindex = 'Y'
BEGIN
DECLARE defrag_cur CURSOR FOR
SELECT ObjectName,
IndexName
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then
don't do anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
DECLARE @.IndexName sysname
DECLARE @.sql varchar(1000)
OPEN defrag_cur
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
WHILE @.@.FETCH_STATUS = 0
BEGIN
PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
indexname=' + @.IndexName
SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
+ @.IndexName + ')'
PRINT @.sql
EXEC( @.sql )
PRINT 'Complete.'
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
END
DEALLOCATE defrag_cur
END
DROP TABLE #fraglist
END
Tony Rogerson
SQL Server MVP
http://www.sqlserverfaq.com?mbr=21
(Create your own groups, Forum, FAQ's and a ton more)
|||This is a very timely thread for me as I'm just getting ready to implement a
SP that is based on the BOL sp.
I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created from
the BOL base is a bit different and I guess I just want to know if the one
if BOL is incorrect or just different.
It determines the indexes to defrag based on the results of:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
if you wanted to exclude clustered indexes I suppose you would be able to
modify to:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
FROM jdit_fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
Thanks
Ivan
"Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
> CREATE PROC ukug2_op_defrag
> @.is_reindex char(1) = 'Y'
> AS
> BEGIN
> SET NOCOUNT ON
> -- Basis of script taken from BOL
> CREATE TABLE #fraglist (
> ObjectName CHAR (255),
> ObjectId INT,
> IndexName CHAR (255),
> IndexId INT,
> Lvl INT,
> CountPages INT,
> CountRows INT,
> MinRecSize INT,
> MaxRecSize INT,
> AvgRecSize INT,
> ForRecCount INT,
> Extents INT,
> ExtentSwitches INT,
> AvgFreeBytes INT,
> AvgPageDensity INT,
> ScanDensity DECIMAL,
> BestCount INT,
> ActualCount INT,
> LogicalFrag DECIMAL,
> ExtentFrag DECIMAL)
> DECLARE tables_cur CURSOR FOR
> SELECT TABLE_NAME
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'BASE TABLE'
> ORDER BY TABLE_NAME
> OPEN tables_cur
> DECLARE @.ObjectName sysname
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
> COUNT_ROWS, NO_INFOMSGS' )
> INSERT #fraglist
> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> END
> CLOSE tables_cur
> DEALLOCATE tables_cur
> SELECT *
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then don't do
> anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> IF @.is_reindex = 'Y'
> BEGIN
> DECLARE defrag_cur CURSOR FOR
> SELECT ObjectName,
> IndexName
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then
> don't do anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> DECLARE @.IndexName sysname
> DECLARE @.sql varchar(1000)
> OPEN defrag_cur
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
> indexname=' + @.IndexName
> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
> + @.IndexName + ')'
> PRINT @.sql
> EXEC( @.sql )
> PRINT 'Complete.'
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> END
> DEALLOCATE defrag_cur
> END
> DROP TABLE #fraglist
> END
>
> --
> Tony Rogerson
> SQL Server MVP
> http://www.sqlserverfaq.com?mbr=21
> (Create your own groups, Forum, FAQ's and a ton more)
>
|||Boy, I wish I could recall messages...I think I answered my own
question--this is for DBREINDEX, not INDEXDEFRAG.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
> This is a very timely thread for me as I'm just getting ready to implement
> a SP that is based on the BOL sp.
> I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
> DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created
> from the BOL base is a bit different and I guess I just want to know if
> the one if BOL is incorrect or just different.
> It determines the indexes to defrag based on the results of:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> FROM #fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> if you wanted to exclude clustered indexes I suppose you would be able to
> modify to:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
> FROM jdit_fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
> Thanks
> Ivan
> "Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
> news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
>
|||Seems like a bit of confusion here. DBCC INDEXDEFRAG can defragment
clustered and non-clustered indexes. DBCC DBREINDEX can rebuild clustered
and non-clustered indexes. The example scripts in this thread are taken from
Example E in BOL for DBCC SHOWCONTIG - look there for more details.
You should read the whitepaper below on fragmentation and when you actually
need to do anything about it (don't just blindly defrag/rebuild everything
in your database - you're wasting resources).
http://www.microsoft.com/technet/pro.../ss2kidbp.mspx
Regards.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:O3CQZhB9EHA.1228@.tk2msftngp13.phx.gbl...[vbcol=seagreen]
> Boy, I wish I could recall messages...I think I answered my own
> question--this is for DBREINDEX, not INDEXDEFRAG.
> "Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
> news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
implement[vbcol=seagreen]
to[vbcol=seagreen]
do[vbcol=seagreen]
''',
>
can dbcc indexdefrag reindex the whole database in one time?
Hi,
Normally i run the DBCC INDEXDEFRAG one table in one time, can run
all the tables in one time?
--
Thank you very much!
Best regards,
FlorenceHi,
This gives DBCC DBREINDEX. You can use this during off-peak hrs, as this is
not an online re-indexing operation. If you still want to use DBCC
INDEXDEFRAG, look at the usage of the same in BOL, and replace it with DBCC
DBREINDEX in given script.
/* Re-indexes the specified database */
CREATE PROCEDURE scr_defrag_database
@.dbname nvarchar(256)
AS
BEGIN
-- Quote the database name with brackets
DECLARE @.quoteddbname nvarchar(256)
SET @.quoteddbname = quotename( @.dbname )
-- The outer EXEC is so we can do USE, not allowed in stored procs
-- The inner EXEC does the actual reindex on each table in the
-- specified database
EXEC('
USE '+ @.quoteddbname +'
DECLARE @.stablename sysname
DECLARE PKMS_Tables CURSOR LOCAL FOR
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = ''BASE TABLE'' ORDER BY 1
OPEN PKMS_Tables
FETCH NEXT FROM PKMS_Tables INTO @.stablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.stablename = quotename(@.stablename, ''[]'')
EXEC('' DBCC DBREINDEX ( ''+@.stablename+'') WITH NO_INFOMSGS'')
FETCH NEXT FROM PKMS_Tables INTO @.stablename
END
CLOSE PKMS_Tables')
END
Thanks
Yogish|||CREATE PROC ukug2_op_defrag
@.is_reindex char(1) = 'Y'
AS
BEGIN
SET NOCOUNT ON
-- Basis of script taken from BOL
CREATE TABLE #fraglist (
ObjectName CHAR (255),
ObjectId INT,
IndexName CHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
DECLARE tables_cur CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_NAME
OPEN tables_cur
DECLARE @.ObjectName sysname
FETCH NEXT FROM tables_cur INTO @.ObjectName
WHILE @.@.FETCH_STATUS = 0
BEGIN
EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH COUNT_ROWS,
NO_INFOMSGS' )
INSERT #fraglist
EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
FETCH NEXT FROM tables_cur INTO @.ObjectName
END
CLOSE tables_cur
DEALLOCATE tables_cur
SELECT *
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then don't do
anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
IF @.is_reindex = 'Y'
BEGIN
DECLARE defrag_cur CURSOR FOR
SELECT ObjectName,
IndexName
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then
don't do anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
DECLARE @.IndexName sysname
DECLARE @.sql varchar(1000)
OPEN defrag_cur
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
WHILE @.@.FETCH_STATUS = 0
BEGIN
PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
indexname=' + @.IndexName
SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
+ @.IndexName + ')'
PRINT @.sql
EXEC( @.sql )
PRINT 'Complete.'
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
END
DEALLOCATE defrag_cur
END
DROP TABLE #fraglist
END
Tony Rogerson
SQL Server MVP
http://www.sqlserverfaq.com?mbr=21
(Create your own groups, Forum, FAQ's and a ton more)|||This is a very timely thread for me as I'm just getting ready to implement a
SP that is based on the BOL sp.
I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created from
the BOL base is a bit different and I guess I just want to know if the one
if BOL is incorrect or just different.
It determines the indexes to defrag based on the results of:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
if you wanted to exclude clustered indexes I suppose you would be able to
modify to:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
FROM jdit_fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
Thanks
Ivan
"Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
> CREATE PROC ukug2_op_defrag
> @.is_reindex char(1) = 'Y'
> AS
> BEGIN
> SET NOCOUNT ON
> -- Basis of script taken from BOL
> CREATE TABLE #fraglist (
> ObjectName CHAR (255),
> ObjectId INT,
> IndexName CHAR (255),
> IndexId INT,
> Lvl INT,
> CountPages INT,
> CountRows INT,
> MinRecSize INT,
> MaxRecSize INT,
> AvgRecSize INT,
> ForRecCount INT,
> Extents INT,
> ExtentSwitches INT,
> AvgFreeBytes INT,
> AvgPageDensity INT,
> ScanDensity DECIMAL,
> BestCount INT,
> ActualCount INT,
> LogicalFrag DECIMAL,
> ExtentFrag DECIMAL)
> DECLARE tables_cur CURSOR FOR
> SELECT TABLE_NAME
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'BASE TABLE'
> ORDER BY TABLE_NAME
> OPEN tables_cur
> DECLARE @.ObjectName sysname
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
> COUNT_ROWS, NO_INFOMSGS' )
> INSERT #fraglist
> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> END
> CLOSE tables_cur
> DEALLOCATE tables_cur
> SELECT *
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then don't do
> anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> IF @.is_reindex = 'Y'
> BEGIN
> DECLARE defrag_cur CURSOR FOR
> SELECT ObjectName,
> IndexName
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then
> don't do anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> DECLARE @.IndexName sysname
> DECLARE @.sql varchar(1000)
> OPEN defrag_cur
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
> indexname=' + @.IndexName
> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
> + @.IndexName + ')'
> PRINT @.sql
> EXEC( @.sql )
> PRINT 'Complete.'
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> END
> DEALLOCATE defrag_cur
> END
> DROP TABLE #fraglist
> END
>
> --
> Tony Rogerson
> SQL Server MVP
> http://www.sqlserverfaq.com?mbr=21
> (Create your own groups, Forum, FAQ's and a ton more)
>|||Boy, I wish I could recall messages...I think I answered my own
question--this is for DBREINDEX, not INDEXDEFRAG.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
> This is a very timely thread for me as I'm just getting ready to implement
> a SP that is based on the BOL sp.
> I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
> DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created
> from the BOL base is a bit different and I guess I just want to know if
> the one if BOL is incorrect or just different.
> It determines the indexes to defrag based on the results of:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> FROM #fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> if you wanted to exclude clustered indexes I suppose you would be able to
> modify to:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
> FROM jdit_fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
> Thanks
> Ivan
> "Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
> news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
>|||Seems like a bit of confusion here. DBCC INDEXDEFRAG can defragment
clustered and non-clustered indexes. DBCC DBREINDEX can rebuild clustered
and non-clustered indexes. The example scripts in this thread are taken from
Example E in BOL for DBCC SHOWCONTIG - look there for more details.
You should read the whitepaper below on fragmentation and when you actually
need to do anything about it (don't just blindly defrag/rebuild everything
in your database - you're wasting resources).
http://www.microsoft.com/technet/pr...n/ss2kidbp.mspx
Regards.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:O3CQZhB9EHA.1228@.tk2msftngp13.phx.gbl...
> Boy, I wish I could recall messages...I think I answered my own
> question--this is for DBREINDEX, not INDEXDEFRAG.
> "Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
> news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
implement[vbcol=seagreen]
to[vbcol=seagreen]
do[vbcol=seagreen]
''',[vbcol=seagreen]
>
Normally i run the DBCC INDEXDEFRAG one table in one time, can run
all the tables in one time?
--
Thank you very much!
Best regards,
FlorenceHi,
This gives DBCC DBREINDEX. You can use this during off-peak hrs, as this is
not an online re-indexing operation. If you still want to use DBCC
INDEXDEFRAG, look at the usage of the same in BOL, and replace it with DBCC
DBREINDEX in given script.
/* Re-indexes the specified database */
CREATE PROCEDURE scr_defrag_database
@.dbname nvarchar(256)
AS
BEGIN
-- Quote the database name with brackets
DECLARE @.quoteddbname nvarchar(256)
SET @.quoteddbname = quotename( @.dbname )
-- The outer EXEC is so we can do USE, not allowed in stored procs
-- The inner EXEC does the actual reindex on each table in the
-- specified database
EXEC('
USE '+ @.quoteddbname +'
DECLARE @.stablename sysname
DECLARE PKMS_Tables CURSOR LOCAL FOR
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = ''BASE TABLE'' ORDER BY 1
OPEN PKMS_Tables
FETCH NEXT FROM PKMS_Tables INTO @.stablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.stablename = quotename(@.stablename, ''[]'')
EXEC('' DBCC DBREINDEX ( ''+@.stablename+'') WITH NO_INFOMSGS'')
FETCH NEXT FROM PKMS_Tables INTO @.stablename
END
CLOSE PKMS_Tables')
END
Thanks
Yogish|||CREATE PROC ukug2_op_defrag
@.is_reindex char(1) = 'Y'
AS
BEGIN
SET NOCOUNT ON
-- Basis of script taken from BOL
CREATE TABLE #fraglist (
ObjectName CHAR (255),
ObjectId INT,
IndexName CHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
DECLARE tables_cur CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_NAME
OPEN tables_cur
DECLARE @.ObjectName sysname
FETCH NEXT FROM tables_cur INTO @.ObjectName
WHILE @.@.FETCH_STATUS = 0
BEGIN
EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH COUNT_ROWS,
NO_INFOMSGS' )
INSERT #fraglist
EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
FETCH NEXT FROM tables_cur INTO @.ObjectName
END
CLOSE tables_cur
DEALLOCATE tables_cur
SELECT *
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then don't do
anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
IF @.is_reindex = 'Y'
BEGIN
DECLARE defrag_cur CURSOR FOR
SELECT ObjectName,
IndexName
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then
don't do anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
DECLARE @.IndexName sysname
DECLARE @.sql varchar(1000)
OPEN defrag_cur
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
WHILE @.@.FETCH_STATUS = 0
BEGIN
PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
indexname=' + @.IndexName
SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
+ @.IndexName + ')'
PRINT @.sql
EXEC( @.sql )
PRINT 'Complete.'
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
END
DEALLOCATE defrag_cur
END
DROP TABLE #fraglist
END
Tony Rogerson
SQL Server MVP
http://www.sqlserverfaq.com?mbr=21
(Create your own groups, Forum, FAQ's and a ton more)|||This is a very timely thread for me as I'm just getting ready to implement a
SP that is based on the BOL sp.
I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created from
the BOL base is a bit different and I guess I just want to know if the one
if BOL is incorrect or just different.
It determines the indexes to defrag based on the results of:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
if you wanted to exclude clustered indexes I suppose you would be able to
modify to:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
FROM jdit_fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
Thanks
Ivan
"Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
> CREATE PROC ukug2_op_defrag
> @.is_reindex char(1) = 'Y'
> AS
> BEGIN
> SET NOCOUNT ON
> -- Basis of script taken from BOL
> CREATE TABLE #fraglist (
> ObjectName CHAR (255),
> ObjectId INT,
> IndexName CHAR (255),
> IndexId INT,
> Lvl INT,
> CountPages INT,
> CountRows INT,
> MinRecSize INT,
> MaxRecSize INT,
> AvgRecSize INT,
> ForRecCount INT,
> Extents INT,
> ExtentSwitches INT,
> AvgFreeBytes INT,
> AvgPageDensity INT,
> ScanDensity DECIMAL,
> BestCount INT,
> ActualCount INT,
> LogicalFrag DECIMAL,
> ExtentFrag DECIMAL)
> DECLARE tables_cur CURSOR FOR
> SELECT TABLE_NAME
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'BASE TABLE'
> ORDER BY TABLE_NAME
> OPEN tables_cur
> DECLARE @.ObjectName sysname
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
> COUNT_ROWS, NO_INFOMSGS' )
> INSERT #fraglist
> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> END
> CLOSE tables_cur
> DEALLOCATE tables_cur
> SELECT *
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then don't do
> anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> IF @.is_reindex = 'Y'
> BEGIN
> DECLARE defrag_cur CURSOR FOR
> SELECT ObjectName,
> IndexName
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then
> don't do anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> DECLARE @.IndexName sysname
> DECLARE @.sql varchar(1000)
> OPEN defrag_cur
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
> indexname=' + @.IndexName
> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
> + @.IndexName + ')'
> PRINT @.sql
> EXEC( @.sql )
> PRINT 'Complete.'
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> END
> DEALLOCATE defrag_cur
> END
> DROP TABLE #fraglist
> END
>
> --
> Tony Rogerson
> SQL Server MVP
> http://www.sqlserverfaq.com?mbr=21
> (Create your own groups, Forum, FAQ's and a ton more)
>|||Boy, I wish I could recall messages...I think I answered my own
question--this is for DBREINDEX, not INDEXDEFRAG.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
> This is a very timely thread for me as I'm just getting ready to implement
> a SP that is based on the BOL sp.
> I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
> DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created
> from the BOL base is a bit different and I guess I just want to know if
> the one if BOL is incorrect or just different.
> It determines the indexes to defrag based on the results of:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> FROM #fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> if you wanted to exclude clustered indexes I suppose you would be able to
> modify to:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
> FROM jdit_fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
> Thanks
> Ivan
> "Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
> news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
>|||Seems like a bit of confusion here. DBCC INDEXDEFRAG can defragment
clustered and non-clustered indexes. DBCC DBREINDEX can rebuild clustered
and non-clustered indexes. The example scripts in this thread are taken from
Example E in BOL for DBCC SHOWCONTIG - look there for more details.
You should read the whitepaper below on fragmentation and when you actually
need to do anything about it (don't just blindly defrag/rebuild everything
in your database - you're wasting resources).
http://www.microsoft.com/technet/pr...n/ss2kidbp.mspx
Regards.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:O3CQZhB9EHA.1228@.tk2msftngp13.phx.gbl...
> Boy, I wish I could recall messages...I think I answered my own
> question--this is for DBREINDEX, not INDEXDEFRAG.
> "Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
> news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
implement[vbcol=seagreen]
to[vbcol=seagreen]
do[vbcol=seagreen]
''',[vbcol=seagreen]
>
Subscribe to:
Posts (Atom)