Before you run the following query, replace <database_name> and <schema_name.object_name> with valid names.
| USE <database_name>; |
Reference: http://msdn.microsoft.com/en-us/library/ms190324.aspx
Adding fuel to my passion on SQL Server
Before you run the following query, replace <database_name> and <schema_name.object_name> with valid names.
| USE <database_name>; |
Reference: http://msdn.microsoft.com/en-us/library/ms190324.aspx
Before you run the following query, replace <database_name> and <n_days> with valid values.
| USE <database_name>; |
Source: http://msdn.microsoft.com/en-us/library/ms190324.aspx
On one of my SQL Server 2008 Instance, the msdb database sizes around 4 GB. I decided to find out the which table / index occupies major junk on this. I have used query below;
| --- Query 1, if there is partition SELECT TOP 10 SERVERNAME=@@SERVERNAME,DB_NAME=DB_NAME(),TABLE_NAME=OBJECT_NAME(I.ID),INDEX_NAME=I.NAME,INDID,USED, ROWS, SIZE_N_MB = ROUND((USED*8.0/1024.0),2), |
| --- Query 2 If there are partitions SELECT object_name(i.object_id) as objectName, |
The output resulted;
The following 5 big tables takes up 88% of the total database size of 3.8 GB. These 5 tables occupy 3.3 GB on the msdb database.
Query 1: Output
| TABLE_NAME | INDEX_NAME | INDID | USED | ROWS | SIZE_N_MB | ROWMODCTR | STATISTICDT |
| backupfile | PK__backupfi__57D1800A17C286CF | 1 | 233057 | 4438738 | 1820.76 | 2646909 | 2/14/2011 15:57 |
| backupset | PK__backupse__21F79AAB0E391C95 | 1 | 115791 | 1489763 | 904.62 | 228112 | 6/19/2011 6:00 |
| backupmediafamily | PK__backupme__0C13C86F0880433F | 1 | 50738 | 1489616 | 396.39 | 23386 | 7/26/2011 7:00 |
| backupfilegroup | PK__backupfi__760CD67A12FDD1B2 | 1 | 43284 | 2967333 | 338.16 | 1775145 | 2/14/2011 15:57 |
| backupmediaset | PK__backupme__DAC69E4D04AFB25B | 1 | 29250 | 1489616 | 228.52 | 44462 | 7/22/2011 15:43 |
| sysjobhistory | clust | 1 | 3553 | 33177 | 27.76 | 2428 | 7/25/2011 8:14 |
Query 2: Output
| objectName | indexName | totalPages | usedPages | dataPages | totalSpaceMB | usedSpaceMB | dataSpaceMB | Rows |
| backupfile | PK__backupfi__57D1800A17C286CF | 233073 | 233043 | 231653 | 1820 | 1820 | 1809 | 4438738 |
| backupset | PK__backupse__21F79AAB0E391C95 | 100217 | 100200 | 99826 | 782 | 782 | 779 | 1489763 |
| backupfilegroup | PK__backupfi__760CD67A12FDD1B2 | 43289 | 43283 | 43077 | 338 | 338 | 336 | 1489616 |
| backupmediafamily | PK__backupme__0C13C86F0880433F | 39473 | 39459 | 39287 | 308 | 308 | 306 | 2967333 |
| backupmediaset | PK__backupme__DAC69E4D04AFB25B | 18737 | 18728 | 18654 | 146 | 146 | 145 | 1489616 |
| SELECT COUNT(*) AS 'TotalRecords', |
Resolution:
The solution is we have to purge these MSDB Backup and Restore history tables
1. The sp_delete_backuphistory system stored procedure takes a single parameter - a cutoff date. Any data older than the supplied date is purged from the msdb tables.
2. The sp_delete_database_backuphistory system stored procedure allows you to delete historical backup data for a specific database. Unfortunately, this procedure does not offer the finer option of choosing a cutoff date. It's all or nothing.
3. sp_purge_jobhistory Removes the history records for a job.
4. Try considering creating indexes on the above said 5 tables, if no of rows are huge.
Source: http://weblogs.sqlteam.com/geoffh/archive/2008/01/21/MSDB-Performance-Tuning.aspx
| use msdb Create index IX_backupset_backup_set_id on backupset(backup_set_id) |
5. Alternatively, check when the statistics of these tables are last updated. Just run sp_updatestats. Just try sp_delete_backuphistory after the statistics are updated. The result is awesome! Very quick response.
Permanent Resolution
6. Further restrict the Job history growth by setting in SQL Agent –> History tab.
7. Also on the SQL Server Maintenance Plan “History Cleanup Task” can be of helpful
In this post I would like to address the requirement of;
SQL Server Database Publishing Wizard enables the deployment of SQL Server databases into a hosted environment on either a SQL Server 2000 or 2005 server.
It generates a single SQL script file which can be used to recreate a database (both schema and data) in a shared hosting environment where the only connectivity to a server is through a web-based control panel with a script execution window.
If supported by the hosting service provider, the Database Publishing Wizard can also directly upload databases to servers located at the shared hosting provider.
We can use the Generate and Publish Scripts Wizard to create scripts for transferring a database from one instance of the Database Engine to another. You can generate scripts for a database on an instance of the Database Engine in your local network, or from SQL Azure.
The generated scripts can be run on another instance of the Database Engine or SQL Azure.
We can also use the wizard to publish the contents of a database directly to a Web service created by using the Database Publishing Services.
We can create scripts for an entire database, or limit it to specific objects.
What version of SQL Servers are supported on this?
| Source Database | Target Database | |
| SQL Server Instance Version Supported |
|
|
| Permission needed | db_ddladmin | db_ddladmin |
| Pre-existence | The target database must be created at the hosting provider before the source database is published. Publishing overwrites objects in that existing database |
Supported Objects for Publishing
The following table lists the objects that can be published and the versions of SQL Server on which they are supported by the Generate and Publish Scripts Wizard.
| Database object | SQL Server 2008 R2 | SQL Server 2008 | SQL Server 2005 | SQL Server 2000 |
| Application role | Yes | Yes | Yes | Yes |
| Assembly | Yes | Yes | Yes | No |
| CHECK constraint | Yes | Yes | Yes | Yes |
| CLR (common language runtime) stored procedure1 | Yes | Yes | Yes | No |
| CLR user-defined function | Yes | Yes | Yes | No |
| Database role | Yes | Yes | Yes | Yes |
| DEFAULT constraint | Yes | Yes | Yes | Yes |
| Full-text catalog | Yes | Yes | Yes | Yes |
| Index | Yes | Yes | Yes | Yes |
| Rule | Yes | Yes | Yes | Yes |
| Schema | Yes | Yes | Yes | No |
| Stored procedure1 | Yes | Yes | Yes | Yes |
| Synonym | Yes | Yes | Yes | Yes |
| Table | Yes | Yes | Yes | Yes |
| User2 | Yes | Yes | Yes | Yes |
| User-defined aggregate | Yes | Yes | Yes | No |
| User-defined data type | Yes | Yes | Yes | Yes |
| User-defined function | Yes | Yes | Yes | Yes |
| User-defined table | Yes | Yes | No | No |
| User-defined type | Yes | Yes | Yes | No |
| View1 | Yes | Yes | Yes | Yes |
| XML schema collection | Yes | Yes | Yes |
1 Published without encryption.
2 Any non-system users that exist in the database are published as Roles.
How to generate SQL Scripts using Generate and Publish Scripts Wizard
We can create Transact-SQL scripts for multiple objects by using the Generate and Publish Scripts Wizard.. You can also generate a script for individual objects or multiple objects by using the Script as menu in Object Explorer.
Use the Generate and Publish Scripts Wizard to create a Transact-SQL script for many objects.
The wizard generates a script of all the objects in a database, or a subset of the objects that you select. The wizard has many options for your scripts, such as whether to include permissions, collation, constraints, and so on.
Step 1:
In Object Explorer, expand Databases, right-click a database, point to Tasks, and then click Generate Scripts. Follow the steps in the wizard to script the database objects.
Script entire database and all database objects
Click to generate scripts for all objects in the database and to include a script for the database itself.
Step 1.3: On the Set Scripting Options page, select Save scripts to a specific location.
Select Save scripts to a specific location
Summary:
Click Finish.
To generate the Script for the Data on the table:
Set “Script Data: True “
Select specific database objects
Click to limit the wizard to generate scripts for only the specific objects in the database that you choose.
For example I have selected Tables Object
Within Tables Object, I have chosen HumanResources.Employee Table
Select Save scripts to a specific location
Script Wizard Summary
View of the Output file generated:
References:
Using the Generate and Publish Scripts Wizard
How to: Generate a Script (SQL Server Management Studio)
To know the status of backup or restore in SQL Server 2000 ;
1. Find the SPID which is restoring the DB using sp_who2 or from sysprocesses
2. Execute dbcc outputbuffer(SPID)
From the output get the %completed status:
Error
• Msg 170, Level 15, State 1, Server MS, Line 1
Line 1: Incorrect syntax near '-'.
The sqlsp.log file indicates:
Process Exit Code: (0)
Error running script: sp_vupgrade_replication (1)
Action CleanUpInstall:
Installation Failed.
Resolution:
1. Check if distribution database exist though the Replication is dropped
2. If so drop the distribution database
3. To drop the distribution database by over - restoring of some user database
4. Perform the patching / SQL SP again.
1. On SQL Server 2000 connect to Enterprise Manager
On SQL Server 2005 / 2008 connect to SQL Server Management studio
2. Expand Replication à Publication, select the Publication from which the subscribers to be removed.
On SQL Server 2005 / 2008 from the Replication à Local Publication select the Publication
3. Right click on the Publication
4. Select the Subscription tab
5. Select the Subscriber and click Delete button, that’s it
6. If you hold the “Shift” key you can delete more than one subscriber. However you have to execute the sp_subscription_cleanup each subscribers manually.
7. Rather if you delete one subscriber at a time, it is simple and no need to execute the stored procedures at subscriber.
sp_reassign_dtspackageowner
powered by performancing firefox