首页 > 数据库

SQL Server script to rebuild all indexes for all tables and all databases

时间:2009-04-23 12:54:28  作者:武树伟  我要投稿
Linux初探欢迎您的投稿,投放方法请点击这里查看,我们会定期赠送精美小礼品给优秀的投稿作者。海纳百川 取则行远!LinuxGoo欢迎您的到来。
SQL Server script to rebuild all indexes for all tables and all databasesWritten By: Edgewood Solutions Engineers -- 11/6/2007 -- 4 commentsStay info......
  • SQL 2005
    • comment this line
      • DBCC DBREINDEX(@Table,' ',@fillfactor)
    • uncomment these lines
      • SET @cmd = 'ALTER INDEX ALL ON ' @Table ' REBUILD WITH (FILLFACTOR = ' CONVERT(VARCHAR(3),@fillfactor) ')'
      • EXEC (@cmd)
  • Also, I have excluded the system databases, so you can include these or also add other databases to exclude from you index maintenance routines.

    Next Steps

    • This is a simple base script that could be modified into a stored procedure and also allow you to pass other parameters such as doing an index rebuild or an index defrag.
    • Make the index rebuild statements more robust with other options.
    • You could also modify this to read from a table that you create to identify which databases you want to run this against instead of using the sysdatabases table.
    • Take a look at these other index related tips
    如果您需转载 SQL Server script to rebuild all indexes for all tables and all databases,请注明来自LinuxGoo.com,其版权归原作者所有。请广大网友留言时遵纪守法,使用文明用语。如果您在应用中有什么问题,请在下面留言,我们会尽快解答。
    来顶一下
    近回首页
    返回首页
    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表
    相关文章
    栏目热门