question

ChaitanyaKiran-2787 avatar image
0 Votes"
ChaitanyaKiran-2787 asked AmeliaGu-msft answered

Do we need to script out statistics?

Good Morning

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

sql-server-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AmeliaGu-msft avatar image
0 Votes"
AmeliaGu-msft answered

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.



image.png (48.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.