SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Server 2005: Script all Indexes


SQL Server 2005: Script all Indexes

Author
Message
tom-580235
tom-580235
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 12
Problem with the script in that if any of your variables are null you don't get the create string produced. i.e., in my experimentation @FileGroupName was null on one of my tables so the Drop index is created but the Create Index is not produced.
Jonathan AC Roberts
Jonathan AC Roberts
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1840 Visits: 1932
tom-580235 (6/17/2013)
Problem with the script in that if any of your variables are null you don't get the create string produced. i.e., in my experimentation @FileGroupName was null on one of my tables so the Drop index is created but the Create Index is not produced.

Which version of the script are you using?
tom-580235
tom-580235
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 12
I am using the last one published.
J.Yogesh
J.Yogesh
SSC Rookie
SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)

Group: General Forum Members
Points: 45 Visits: 56
I have i doubt

when I recreated an index using this script ,I found 1 difference in FILLFACTOR value in case of '0'

----------------------------------------------
This is what I generated before this script
----------------------------------------------
CREATE NONCLUSTERED INDEX [ABC_StudentIdCardNumber] ON [dbo].[StudentAccounts]
( [StudentIdcardNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF
, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

----------------------------------------------
Then i drop the indexes and create it again using the script generated with above script & again generate Create Script
----------------------------------------------

CREATE NONCLUSTERED INDEX [ABC_StudentIdCardNumber1] ON [dbo].[StudentAccounts]
( [StudentIdcardNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF
, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, = 100) ON [PRIMARY]
GO
----------------------------------------------
Are these 2 create index scripts technically same of OR script needs some correction ?
meghamittal166
meghamittal166
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 9
Rephrasing my query. Currently the create index script is coming as a message. Can we have the complete message as a table column. Actually , I am calling this stored procedure from JAVA. There is no function in Java to get the messages returned by script but java can capture the table column of the table returned by the stored procedure.

Please help.
Sherbaz.com
Sherbaz.com
Grasshopper
Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)

Group: General Forum Members
Points: 19 Visits: 56
Hi,

I have modified the script to output the files in a table format and posted in my blog.

http://www.sherbaz.com/2015/03/list-out-and-script-all-indexes-in-a-database-for-excel-sheets/

Have a look and let me know if you have any queries.

Thanks and regards
Sherbaz
www.sherbaz.com


Developer and DBA
@

www.splitexpense.in


yan-160997
yan-160997
SSC Veteran
SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)

Group: General Forum Members
Points: 207 Visits: 324
@r5d4, thank you for your information. I have the same problem, and ran your script. The script only generate the scripts for normal indexes, which does not include PK (clustered) in the index category. Any idea what to do?


Thanks

Yan
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search