<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>history table &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/history-table/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Wed, 28 Feb 2018 03:21:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server 2016: Enable System-versioned Temporal Table on existing Table</title>
		<link>https://www.dbrnd.com/2018/03/sql-server-2016-enable-system-versioned-temporal-table-on-existing-table-system_versioning-history_table/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 07 Mar 2018 16:16:19 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[history table]]></category>
		<category><![CDATA[history_table]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[system_versioning]]></category>
		<category><![CDATA[system-versioned temporal table]]></category>
		<category><![CDATA[track data change]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4284</guid>

					<description><![CDATA[SQL Server 2016 introduced System-versioned Temporal Table to keep a history of data change by adding additional history table. In the below article, You can read more about System-versioned Temporal Table and you must know all the rules before creating a System-versioned Temporal Table. You can also enable System-versioned Temporal Table in the existing table. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-enable-system-versioned-temporal-table-on-existing-table-system_versioning-history_table%2F&amp;linkname=SQL%20Server%202016%3A%20Enable%20System-versioned%20Temporal%20Table%20on%20existing%20Table" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-enable-system-versioned-temporal-table-on-existing-table-system_versioning-history_table%2F&amp;linkname=SQL%20Server%202016%3A%20Enable%20System-versioned%20Temporal%20Table%20on%20existing%20Table" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-enable-system-versioned-temporal-table-on-existing-table-system_versioning-history_table%2F&amp;linkname=SQL%20Server%202016%3A%20Enable%20System-versioned%20Temporal%20Table%20on%20existing%20Table" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-enable-system-versioned-temporal-table-on-existing-table-system_versioning-history_table%2F&amp;linkname=SQL%20Server%202016%3A%20Enable%20System-versioned%20Temporal%20Table%20on%20existing%20Table" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-enable-system-versioned-temporal-table-on-existing-table-system_versioning-history_table%2F&amp;linkname=SQL%20Server%202016%3A%20Enable%20System-versioned%20Temporal%20Table%20on%20existing%20Table" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-enable-system-versioned-temporal-table-on-existing-table-system_versioning-history_table%2F&amp;linkname=SQL%20Server%202016%3A%20Enable%20System-versioned%20Temporal%20Table%20on%20existing%20Table" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-enable-system-versioned-temporal-table-on-existing-table-system_versioning-history_table%2F&#038;title=SQL%20Server%202016%3A%20Enable%20System-versioned%20Temporal%20Table%20on%20existing%20Table" data-a2a-url="https://www.dbrnd.com/2018/03/sql-server-2016-enable-system-versioned-temporal-table-on-existing-table-system_versioning-history_table/" data-a2a-title="SQL Server 2016: Enable System-versioned Temporal Table on existing Table"></a></p><p>SQL Server 2016 introduced System-versioned Temporal Table to keep a history of data change by adding additional history table.</p>
<p>In the below article, You can read more about System-versioned Temporal Table and you must know all the rules before creating a System-versioned Temporal Table.</p>
<p>You can also enable System-versioned Temporal Table in the existing table.</p>
<p><strong>Check this demonstration:</strong></p>
<p><strong>Create a table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Employees
(
	EmpID INT PRIMARY KEY
	,EmpName VARCHAR(20)
	,EmpDepartment VARCHAR(20)
	,EmpSalary INT
)
GO
 
INSERT INTO tbl_Employees
VALUES 
(1,'Anvesh','Database',90000)
,(2,'Jenny','JAVA',65000)
,(3,'Martin','PHP',85000)
,(4,'Roy','PHP',94000)
GO</pre> </p>
<p><strong>Enable System-versioned Temporal Table on this table:</strong></p>
<pre class="crayon-plain-tag">ALTER TABLE tbl_Employees
SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE=dbo.tbl_EmployeesHistory))
GO</pre> </p>
<p>You will get a below error because you must configure SYSTEM_TIME column. </p>
<pre class="crayon-plain-tag">Msg 13510, Level 16, State 1, Line 1
Cannot set SYSTEM_VERSIONING to ON when SYSTEM_TIME period is not defined.</pre> </p>
<p><strong>Configure SYSTEM_TIME column:</strong></p>
<pre class="crayon-plain-tag">ALTER TABLE tbl_Employees
ADD 
	StartTime DATETIME2 GENERATED ALWAYS AS ROW START DEFAULT GETUTCDATE()
	,EndTime DATETIME2 GENERATED ALWAYS AS ROW END DEFAULT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999') 
	,PERIOD FOR SYSTEM_TIME (StartTime, EndTime)  
GO</pre> </p>
<p><strong>Now, enable System-versioned Temporal Table:</strong></p>
<pre class="crayon-plain-tag">ALTER TABLE tbl_Employees
SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE=dbo.tbl_EmployeesHistory))
GO</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server 2016: System-versioned Temporal Table to store History of data change</title>
		<link>https://www.dbrnd.com/2018/03/sql-server-2016-system-versioned-temporal-table-to-store-history-of-data-change/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 05 Mar 2018 16:16:36 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Change data capture]]></category>
		<category><![CDATA[Data change audit]]></category>
		<category><![CDATA[data history]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[DDL Changes]]></category>
		<category><![CDATA[history table]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[System-versioned]]></category>
		<category><![CDATA[Temporal Table]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4261</guid>

					<description><![CDATA[<div><img width="651" height="398" src="https://www.dbrnd.com/wp-content/uploads/2018/02/History.jpg" class="attachment-post-image size-post-image wp-post-image" alt="" decoding="async" fetchpriority="high" /></div>SQL Server 2016 introduced a new type of user table that is called System-versioned Temporal Table to keep a full history of data changes. This is a very good addition to the SQL Server 2016 because to track data change history is always an important task for a big transactional system. SQL Server already provides [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="651" height="398" src="https://www.dbrnd.com/wp-content/uploads/2018/02/History.jpg" class="attachment-post-image size-post-image wp-post-image" alt="" decoding="async" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-system-versioned-temporal-table-to-store-history-of-data-change%2F&amp;linkname=SQL%20Server%202016%3A%20System-versioned%20Temporal%20Table%20to%20store%20History%20of%20data%20change" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-system-versioned-temporal-table-to-store-history-of-data-change%2F&amp;linkname=SQL%20Server%202016%3A%20System-versioned%20Temporal%20Table%20to%20store%20History%20of%20data%20change" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-system-versioned-temporal-table-to-store-history-of-data-change%2F&amp;linkname=SQL%20Server%202016%3A%20System-versioned%20Temporal%20Table%20to%20store%20History%20of%20data%20change" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-system-versioned-temporal-table-to-store-history-of-data-change%2F&amp;linkname=SQL%20Server%202016%3A%20System-versioned%20Temporal%20Table%20to%20store%20History%20of%20data%20change" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-system-versioned-temporal-table-to-store-history-of-data-change%2F&amp;linkname=SQL%20Server%202016%3A%20System-versioned%20Temporal%20Table%20to%20store%20History%20of%20data%20change" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-system-versioned-temporal-table-to-store-history-of-data-change%2F&amp;linkname=SQL%20Server%202016%3A%20System-versioned%20Temporal%20Table%20to%20store%20History%20of%20data%20change" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-2016-system-versioned-temporal-table-to-store-history-of-data-change%2F&#038;title=SQL%20Server%202016%3A%20System-versioned%20Temporal%20Table%20to%20store%20History%20of%20data%20change" data-a2a-url="https://www.dbrnd.com/2018/03/sql-server-2016-system-versioned-temporal-table-to-store-history-of-data-change/" data-a2a-title="SQL Server 2016: System-versioned Temporal Table to store History of data change"></a></p><p>SQL Server 2016 introduced a new type of user table that is called System-versioned Temporal Table to keep a full history of data changes.</p>
<p>This is a very good addition to the SQL Server 2016 because to track data change history is always an important task for a big transactional system.</p>
<p>SQL Server already provides few features to track data change like Change Data Capture (CDC), SQL Server Auditing, can create a manual DDL Trigger.</p>
<blockquote><p>Now, SQL Server 2016 System-versioned temporal table which is something good and very easy to implement on a specific table.<br />
You can audit all data changes and can perform require analysis on it. In Case of invalid delete or update, you can recover your data.</p></blockquote>
<p><strong>Rules and Requirements:</strong></p>
<ul>
<li>Can create your table using SYSTEM_VERSIONING=ON</li>
<li>Define your history table name HISTORY_TABLE = TableName, which tracks data change history. (It creates automatically).</li>
<li>Must define two additional columns [ValidFrom] and [ValidTo] with default ROW START and ROW END and must refer to as SYSTEM_TIME period columns.</li>
<li>Must have a Primary key column.</li>
<li>Same number of column and structure between both the tables.</li>
</ul>
<p><strong>Full demonstration:</strong></p>
<p><strong>Create a sampel System Version Table:</strong><br />
<pre class="crayon-plain-tag">CREATE TABLE tbl_Students
(
	StudID INT PRIMARY KEY
	,StudName VARCHAR(50)
	,StudClass CHAR(1)
	,ValidFrom DATETIME2 (2) GENERATED ALWAYS AS ROW START  
	,ValidTo DATETIME2 (2) GENERATED ALWAYS AS ROW END  
	,PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo)  
) WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.tbl_StudentsHistory));  
GO</pre>
<p><strong>Insert few sample records:</strong><br />
<pre class="crayon-plain-tag">INSERT INTO tbl_Students 
(StudID,StudName,StudClass)
VALUES (1,'Roy','A'),(2,'Bony','B'),(3,'Mahi','C')
,(4,'Maria','A'),(5,'Ron','B'),(6,'Murey','C')
GO</pre>
<p><strong>Execute few DML statements:</strong><br />
<pre class="crayon-plain-tag">UPDATE tbl_Students SET StudClass = 'B'
WHERE StudID = 4;
GO

DELETE FROM tbl_Students WHERE StudID = 2
GO</pre>
<p><strong>Check the result of both tables:</strong><br />
<pre class="crayon-plain-tag">SELECT *FROM tbl_StudentsHistory

StudID  StudName      StudClass ValidFrom                   ValidTo
------- ------------- --------- --------------------------- ---------------------------
4       Maria             A         2017-01-06 05:47:23.73      2017-01-06 05:48:54.43
2       Bony              B         2017-01-06 05:47:23.73      2017-01-06 05:50:12.52


SELECT *FROM tbl_Students

StudID  StudName        StudClass ValidFrom                   ValidTo
------- --------------- --------- --------------------------- ---------------------------
1       Roy                 A         2017-01-06 05:47:23.73      9999-12-31 23:59:59.99
3       Mahi                C         2017-01-06 05:47:23.73      9999-12-31 23:59:59.99
4       Maria               B         2017-01-06 05:48:54.43      9999-12-31 23:59:59.99
5       Ron                 B         2017-01-06 05:47:23.73      9999-12-31 23:59:59.99
6       Murey               C         2017-01-06 05:47:23.73      9999-12-31 23:59:59.99</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
