Site sponsored by: Idera The gold standard of SQL Server performance monitoring & diagnostics.
SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Quiz
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
Developer
General DBA
ASP.NET / ADO.NET

Write for Us

Share you SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

Claytons Data Mining (Part 2)
Backup System Databases Using Maintenance Plans
Overview of Maintenance Plans in SQL Server 2008
Monitoring Index Fragmentation

More     
 
Latest FAQ's

How to alter a User Defined Data Type?
How to unzip a File in SSIS?
How to view previous query plans?
ALTER TABLE SWITCH statement failed because the object '%.*ls' is not ...

More     
   
Latest Software Reviews

Spotlight on ApexSQL Doc 2008
ApexSQL Enforce
Embarcadero Change Manager
SQL Server DBA Dashboard

More     

articles >> performance tuning >> Transferring SQL Server Statistics From One Database ...

Transferring SQL Server Statistics From One Database to Another

By : Joe Chang
Feb 16, 2005

Page 4 / 4

INSERT sysindexes(id,status,first,indid,root,minlen,keycnt,groupid,dpages,reserved,used,rowcnt, rowmodctr,reserved3,reserved4,xmaxlen,maxirow,OrigFillFactor,StatVersion, reserved2,FirstIAM,impid,lockflags,pgmodctr,keys,name,statblob)

SELECT o.id, status,first,indid,root,minlen,keycnt,groupid,dpages,reserved,used,rowcnt,

rowmodctr,reserved3, reserved4,xmaxlen,maxirow,OrigFillFactor,StatVersion,

reserved2,FirstIAM,impid,lockflags,pgmodctr,keys,s.name,statblob

FROM [tindexes] s

INNER JOIN [tobjects] o

ON o.oid = s.id

WHERE  (s.status & 64) = 64

GO

 

Create Nonclustered Indexes and Update Sysindexes

Once the statistics not associated with indexes have been inserted into the sysindexes table, the nonclustered indexes can be created. It does not matter if the indid value for the nonclustered indexes matches to the original indid value. The statement below updates the new sysindexes table with required statistics data from the copy of the original sysindexes table.

UPDATE i SET dpages = s.dpages, reserved = s.reserved, used = s.used, rowcnt = s.rowcnt, rowmodctr = s.rowmodctr, statblob = s.statblob

FROM sysindexes i

INNER JOIN [tobjects] t ON t.id = i.id

INNER JOIN [tindexes] s ON s.id = t.oid AND s.name = i.name

WHERE (s.status & 64) = 0

GO

Run sp_configure to disallow updates to system tables at this time. The new database can now be backed up or detached for transfer to other systems. Any necessary data for the new small sized database can be transferred at any time during this process.

 

Summary

A description of the steps to transfer statistics from one database to another has been presented. This is probably most useful when it is necessary to display the execution plan that would be used on the large production database from a smaller sized database. Developers can work on a database generated from the scripts and still observe the production execution plan, with the exception of parallel execution plans if the development system is single processor.

Other potential uses include allowing a person to troubleshoot performance issues due to problem execution plans that can only be seen from the production database statistics data. The scripts for the required tables and indexes can be transferred to a new database along with statistics. This small amount of data can be sent by email for remote troubleshooting.

 

2004 Joe Chang. All rights reserved. Published with the express written permission of the author.


<< Prev Page         








Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | QDPMA Performance Tuning | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 1999-2008 by T10 Media. All rights reserved