<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://sbv.wiki/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://sbv.wiki/index.php?action=history&amp;feed=atom&amp;title=Maintenance</id>
		<title>Maintenance - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://sbv.wiki/index.php?action=history&amp;feed=atom&amp;title=Maintenance"/>
		<link rel="alternate" type="text/html" href="http://sbv.wiki/index.php?title=Maintenance&amp;action=history"/>
		<updated>2026-04-08T08:10:46Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.22.5</generator>

	<entry>
		<id>http://sbv.wiki/index.php?title=Maintenance&amp;diff=565&amp;oldid=prev</id>
		<title>Stage: /* Database Maintenance */</title>
		<link rel="alternate" type="text/html" href="http://sbv.wiki/index.php?title=Maintenance&amp;diff=565&amp;oldid=prev"/>
				<updated>2015-05-17T17:16:13Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Database Maintenance&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 17:16, 17 May 2015&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 63:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 63:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; bcp &amp;quot;SELECT * from Ta..Audit WHERE DatabaseDateTime &amp;gt;= '01/01/2015' AND DatabaseDateTime &amp;lt; '01/01/2016'&amp;quot; queryout audit2015.txt -c -S SERVER\INSTANCE -U user -P password -o audit2015.log&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; bcp &amp;quot;SELECT * from Ta..Audit WHERE DatabaseDateTime &amp;gt;= '01/01/2015' AND DatabaseDateTime &amp;lt; '01/01/2016'&amp;quot; queryout audit2015.txt -c -S SERVER\INSTANCE -U user -P password -o audit2015.log&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;By using a similar script for each year that the database has been in use, you will create a text file for each year that contains the contents of the audit table. We recommend that you then zip up each year so that you do not accidentially overwrite these files on subsequent purges. The zip will contain both the log and the data for reference. A 100 Mb text file represents ~ &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;1,000&lt;/del&gt;,000 rows of the Audit table.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;By using a similar script for each year that the database has been in use, you will create a text file for each year that contains the contents of the audit table. We recommend that you then zip up each year so that you do not accidentially overwrite these files on subsequent purges. The zip will contain both the log and the data for reference. A 100 Mb text file represents ~ &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;800&lt;/ins&gt;,000 rows of the Audit table &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;and when zipped will be ~10% of the size. For example, one million audit records will end up as a ~15Mb zip file&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt; &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The file from the current calendar year should not be zipped up. This is going to be reloaded back into the Audit table once the table is completely purged.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The file from the current calendar year should not be zipped up. This is going to be reloaded back into the Audit table once the table is completely purged.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Stage</name></author>	</entry>

	<entry>
		<id>http://sbv.wiki/index.php?title=Maintenance&amp;diff=564&amp;oldid=prev</id>
		<title>Stage: Created page with &quot;{{Advanced}}  == Software Maintenance ==  {{Under Construction}}  == HandPunch Maintenance ==  See HandPunch Maintenance  == Database Maintenance ==  {{Under Construction}...&quot;</title>
		<link rel="alternate" type="text/html" href="http://sbv.wiki/index.php?title=Maintenance&amp;diff=564&amp;oldid=prev"/>
				<updated>2015-05-17T16:52:23Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Advanced}}  == Software Maintenance ==  {{Under Construction}}  == HandPunch Maintenance ==  See &lt;a href=&quot;/HandPunch_Maintenance&quot; title=&quot;HandPunch Maintenance&quot;&gt;HandPunch Maintenance&lt;/a&gt;  == Database Maintenance ==  {{Under Construction}...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Advanced}}&lt;br /&gt;
&lt;br /&gt;
== Software Maintenance ==&lt;br /&gt;
&lt;br /&gt;
{{Under Construction}}&lt;br /&gt;
&lt;br /&gt;
== HandPunch Maintenance ==&lt;br /&gt;
&lt;br /&gt;
See [[HandPunch Maintenance]]&lt;br /&gt;
&lt;br /&gt;
== Database Maintenance ==&lt;br /&gt;
&lt;br /&gt;
{{Under Construction}}&lt;br /&gt;
&lt;br /&gt;
As the database maintains an audit log of all changes made in the software, the database will grow to be very large in size after a few years. It is not practical to keep the contents of the audit table as this can account for over 50% of the size of your database.&lt;br /&gt;
&lt;br /&gt;
The following SQL script will show you the number of rows in each of your database tables:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;SELECT &lt;br /&gt;
    [TableName] = so.name, &lt;br /&gt;
    [RowCount] = MAX(si.rows) &lt;br /&gt;
FROM &lt;br /&gt;
    sysobjects so &lt;br /&gt;
INNER JOIN &lt;br /&gt;
    sysindexes si &lt;br /&gt;
ON &lt;br /&gt;
    si.id = OBJECT_ID(so.name) &lt;br /&gt;
WHERE &lt;br /&gt;
    OBJECTPROPERTY(so.id, 'IsMsShipped') = 0 &lt;br /&gt;
    AND so.xtype = 'U' &lt;br /&gt;
GROUP BY &lt;br /&gt;
    so.name &lt;br /&gt;
ORDER BY &lt;br /&gt;
    2 DESC;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The results of this query are: &lt;br /&gt;
&lt;br /&gt;
 Audit                  9472425&lt;br /&gt;
 Schedule	       2098028&lt;br /&gt;
 Punch	                844036&lt;br /&gt;
 RawPunch	        843681&lt;br /&gt;
 Hours	                561563&lt;br /&gt;
 Exception	        516282&lt;br /&gt;
 EmployeeHistory           4788&lt;br /&gt;
 SavedReportSelection	  3552&lt;br /&gt;
 Comment                   2400&lt;br /&gt;
 Assignment	          1942&lt;br /&gt;
 EmployeeStatus	          1405&lt;br /&gt;
 EmployeeShift	          1080&lt;br /&gt;
 EmployeeClockID            911&lt;br /&gt;
 EmployeeExtended	   850&lt;br /&gt;
 Employee	           849&lt;br /&gt;
 EmployeeEmployment	   638&lt;br /&gt;
 PayPeriod	           394&lt;br /&gt;
 OvertimePeriod	           384&lt;br /&gt;
 EmployeeHealth	           336&lt;br /&gt;
 EmployeeLicensing	   336 .....&lt;br /&gt;
&lt;br /&gt;
The audit table in this example of a single facility database used for 6 years. The database is ~7 Gb in size.&lt;br /&gt;
&lt;br /&gt;
The fastest method of getting data out of the database is by using the bcp command. An example of this is:&lt;br /&gt;
&lt;br /&gt;
 bcp &amp;quot;SELECT * from Ta..Audit WHERE DatabaseDateTime &amp;gt;= '01/01/2015' AND DatabaseDateTime &amp;lt; '01/01/2016'&amp;quot; queryout audit2015.txt -c -S SERVER\INSTANCE -U user -P password -o audit2015.log&lt;br /&gt;
&lt;br /&gt;
By using a similar script for each year that the database has been in use, you will create a text file for each year that contains the contents of the audit table. We recommend that you then zip up each year so that you do not accidentially overwrite these files on subsequent purges. The zip will contain both the log and the data for reference. A 100 Mb text file represents ~ 1,000,000 rows of the Audit table.&lt;br /&gt;
&lt;br /&gt;
The file from the current calendar year should not be zipped up. This is going to be reloaded back into the Audit table once the table is completely purged.&lt;br /&gt;
&lt;br /&gt;
The following script will drop and recreate the Audit table:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Audit]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)&lt;br /&gt;
drop table [dbo].[Audit]&lt;br /&gt;
GO&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE [dbo].[Audit] (&lt;br /&gt;
	[PkAuditID] [bigint] NOT NULL ,&lt;br /&gt;
	[FkLoggedInID] [bigint] NULL ,&lt;br /&gt;
	[FkEmployeeID] [bigint] NULL ,&lt;br /&gt;
	[Object] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,&lt;br /&gt;
	[FkObjectID] [bigint] NULL ,&lt;br /&gt;
	[Method] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,&lt;br /&gt;
	[Value] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,&lt;br /&gt;
	[PreviousValue] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,&lt;br /&gt;
	[ComputerName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,&lt;br /&gt;
	[ComputerLoginName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,&lt;br /&gt;
	[ComputerDateTime] [datetime] NULL ,&lt;br /&gt;
	[DatabaseDateTime] [datetime] NULL ,&lt;br /&gt;
	[FkCreatedByID] [bigint] NULL ,&lt;br /&gt;
	[CreatedDateTime] [datetime] NULL ,&lt;br /&gt;
	[FkUpdatedByID] [bigint] NULL ,&lt;br /&gt;
	[UpdatedDateTime] [datetime] NULL ,&lt;br /&gt;
	[FkDeletedByID] [bigint] NULL ,&lt;br /&gt;
	[DeletedDateTime] [datetime] NULL ,&lt;br /&gt;
	[Deleted] [bit] NULL &lt;br /&gt;
) ON [PRIMARY]&lt;br /&gt;
GO&lt;br /&gt;
&lt;br /&gt;
ALTER TABLE [dbo].[Audit] WITH NOCHECK ADD &lt;br /&gt;
	CONSTRAINT [PK_Audit] PRIMARY KEY  CLUSTERED &lt;br /&gt;
	(&lt;br /&gt;
		[PkAuditID]&lt;br /&gt;
	) WITH  FILLFACTOR = 90  ON [PRIMARY] &lt;br /&gt;
GO&lt;br /&gt;
&lt;br /&gt;
CREATE  INDEX [IX_FkLoggedInID] ON [dbo].[Audit]([FkLoggedInID]) WITH  FILLFACTOR = 90 ON [PRIMARY]&lt;br /&gt;
GO&lt;br /&gt;
&lt;br /&gt;
CREATE  INDEX [IX_FkEmployeeID] ON [dbo].[Audit]([FkEmployeeID]) WITH  FILLFACTOR = 90 ON [PRIMARY]&lt;br /&gt;
GO&lt;br /&gt;
&lt;br /&gt;
CREATE  INDEX [IX_Object] ON [dbo].[Audit]([Object]) WITH  FILLFACTOR = 90 ON [PRIMARY]&lt;br /&gt;
GO&lt;br /&gt;
&lt;br /&gt;
CREATE  INDEX [IX_FkObjectID] ON [dbo].[Audit]([FkObjectID]) WITH  FILLFACTOR = 90 ON [PRIMARY]&lt;br /&gt;
GO&lt;br /&gt;
&lt;br /&gt;
CREATE  INDEX [IX_Method] ON [dbo].[Audit]([Method]) WITH  FILLFACTOR = 90 ON [PRIMARY]&lt;br /&gt;
GO&lt;br /&gt;
&lt;br /&gt;
CREATE  INDEX [IX_DatabaseDateTime] ON [dbo].[Audit]([DatabaseDateTime]) WITH  FILLFACTOR = 90 ON [PRIMARY]&lt;br /&gt;
GO&lt;br /&gt;
&lt;br /&gt;
CREATE  INDEX [IX_PkAuditID_Object] ON [dbo].[Audit]([PkAuditID], [Object]) ON [PRIMARY]&lt;br /&gt;
GO&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Audit table and now empty and the current year's file is now loaded back.&lt;br /&gt;
&lt;br /&gt;
 bcp Ta..Audit in audit2015.txt -c -S SERVER\INSTANCE -U user -P password -o loadaudit2015.log&lt;br /&gt;
&lt;br /&gt;
We recommend that you confirm the number of rows in the log file create when dumping the current year's data with the number of rows loaded back into the database.&lt;br /&gt;
&lt;br /&gt;
This is what shows in the log file:&lt;br /&gt;
&lt;br /&gt;
 385877 rows copied.&lt;br /&gt;
&lt;br /&gt;
Here is a query that gives us the total number of rows in the Audit table:&lt;br /&gt;
&lt;br /&gt;
 SELECT COUNT(*) FROM Audit&lt;br /&gt;
&lt;br /&gt;
Upon seeing that the results are identical you can continue.&lt;br /&gt;
&lt;br /&gt;
Shrinking this database reduced the size from ~7Gb to less than 3Gb.&lt;/div&gt;</summary>
		<author><name>Stage</name></author>	</entry>

	</feed>