If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > Need a way to automate index rebuild statements.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-01-08, 20:02
t01a9be t01a9be is offline
Registered User
 
Join Date: Mar 2008
Posts: 2
Need a way to automate index rebuild statements.

Hi Everyone,

I am looking for a way to automate a script building process to rebuild
indexes in SYBASE. I have a database with hundreds of indexes I need to rebuild.
Currently I have been creating the drop, and create index statements manually.
Does anyone have an example of a script I can use to build these statements from sysindex or
another system table in SYBASE.

I have included some examples of the scripts I use below. I am using SYBASE version 12.



drop index policy_claim_xref.policy_claim_xref_pk
drop index imbf_request.imbf_request_x02
drop index imbf_request.imbf_request_x03
drop index imbf_request.imbf_request_x03
drop index imbf_request.imbf_request_x05



create unique clustered index policy_claim_xref_pk
on dm0101d.dbo.policy_claim_xref ( policy_number, claim_number)
on 'dmsimg_data_seg1'

create nonclustered index imbf_request_x02
on dm0101d.dbo.imbf_request ( request_date)
create nonclustered index imbf_request_x03
on dm0101d.dbo.imbf_request ( complete_date)
create unique nonclustered index imbf_request_x04
on dm0101d.dbo.imbf_request ( folder_number)
create nonclustered index imbf_request_x05
on dm0101d.dbo.imbf_request ( status_code)
Reply With Quote
  #2 (permalink)  
Old 04-03-08, 19:15
t01a9be t01a9be is offline
Registered User
 
Join Date: Mar 2008
Posts: 2
Bump it up

Wanted to bump this up to the top.
Reply With Quote
  #3 (permalink)  
Old 04-04-08, 03:27
Martijnvs Martijnvs is offline
Registered User
 
Join Date: Jan 2004
Location: The Hague/Utrecht, NL
Posts: 415
I think that requiers some serious digging in systemtables. Starting with sysobjects for the name of the index, joining it with other tables to find the type (clustered/nonclustered) and the columns.
It's a challenge, but a time-consuming one.
__________________
I'm not crazy, I'm an aeroplane!
Reply With Quote
  #4 (permalink)  
Old 04-04-08, 06:46
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Have a look at sp__revindex
The procs can be downloaded from http://www.edbarlow.com/download/procs.tgz
Reply With Quote
  #5 (permalink)  
Old 04-07-08, 12:27
pvvsnaveen pvvsnaveen is offline
Registered User
 
Join Date: Feb 2007
Location: India
Posts: 56
Hi,

Here i have one point

when you are creating a clustered index means non-clustered indexes will automatically rebuild. no need to drop and create of non-clustered indexes.

So your work will be reduced to 1/3 now.

select "sp_rebuildindex "+name from sysindexes where indid=1


Regards,
Naveen.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On