Do we need to script out statistics?

Chaitanya Kiran 696 Reputation points
2021-11-10T06:07:16.703+00:00

Good Morning

When migrating a database, do we need to script out statistics?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,646 questions
0 comments No comments
{count} votes

Accepted answer
  1. AmeliaGu-MSFT 13,961 Reputation points Microsoft Vendor
    2021-11-10T08:09:41.63+00:00

    Hi ChaitanyaKiran-2787,

    Statistics are important for performance and are essential for the query optimizer to prepare an optimized and cost-effective execution plan. So I think we need to script out statistics when migrating.
    If you migrate database using backup file, then we don’t need to script out statistics cause the statistics are included in the .bak file.
    You can right-click on the database name -> Tasks -> select Generate Scripts in the SSMS.
    In the Set Scripting Options tab, click Advanced and set script statistics to Script statistics and histograms.

    148105-image.png

    Please refer to this article which might be helpful.

    Best Regards,
    Amelia


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful