Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

Copying Database Statistics and Schema to New Database

$
0
0

Host: SQL Server 2005 (32-bit) Standard Edition

I'm tuning a query that is performing poorly in production. I want to (a) work with the query on a non-production server and (b) don't want to clone the database on that server. I would like to recreate the schema with statistics and histograms in development as they exist in production. My intention is to run the offending query in development still getting the same execution plan as in production.

I'm creating a new database, setting auto create statistics, auto update statistics, and auto update statistics async off:

CREATE DATABASE [Sandbox];
GO
ALTER DATABASE [Sandbox] SET AUTO_CREATE_STATISTICS OFF;
ALTER DATABASE [Sandbox] SET AUTO_UPDATE_STATISTICS OFF;
ALTER DATABASE [Sandbox] SET AUTO_UPDATE_STATISTICS_ASYNC OFF;
GO
I'm then creating a few user-specified types, table, and indexes. After that, I'm creating and updating  

CREATE STATISTICS [_WA_Sys_0000000A_2D27B809] ON [dbo].[Table]([PrimaryObjectType]) WITH STATS_STREAM = 0x01...
CREATE STATISTICS [_WA_Sys_0000000D_2D27B809] ON [dbo].[Table]([SecondaryObjectType]) WITH STATS_STREAM = 0x01...
UPDATE STATISTICS [dbo].[Table]([IX_LastModifiedTime_Table]) WITH STATS_STREAM = 0x01..., ROWCOUNT = 19276518, PAGECOUNT = 45401
UPDATE STATISTICS [dbo].[Table]([IX_MessageType_Table]) WITH STATS_STREAM = 0x01..., ROWCOUNT = 19276518, PAGECOUNT = 106613
UPDATE STATISTICS [dbo].[Table]([IX_MessageUTC_Table]) WITH STATS_STREAM = 0x01..., ROWCOUNT = 19276518, PAGECOUNT = 130230
UPDATE STATISTICS [dbo].[Table]([IX_ObjectIndex_Table]) WITH STATS_STREAM = 0x01..., ROWCOUNT = 19276518, PAGECOUNT = 45393
UPDATE STATISTICS [dbo].[Table]([IX_PrimaryObjectIdentity_Table]) WITH STATS_STREAM = 0x01..., ROWCOUNT = 19276518, PAGECOUNT = 73322
UPDATE STATISTICS [dbo].[Table]([IX_PrimaryObjectName_Table]) WITH STATS_STREAM = 0x01..., ROWCOUNT = 19276518, PAGECOUNT = 142496

Lastly, I add the table's constraints.

F.Y.I., I'm scripting out the schema, dependent objects, indexes, and statistics/histograms from Object Explorer.

When I run the query, it generates with a different execution plan. What am I doing wrong?


Adam


Viewing all articles
Browse latest Browse all 12963

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>