<?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>Partitions &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/partitions/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, 27 Sep 2017 20:36:49 +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: Introduce New TRUNCATE  by Partitions Number</title>
		<link>https://www.dbrnd.com/2016/01/sql-server-2016-introduce-new-truncate-by-partitions-number/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 08 Jan 2016 18:02:13 +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[Partitions]]></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[truncate]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1181</guid>

					<description><![CDATA[In this post, I am sharing a new version of TRUNCATE command which used to truncate the partitions and newly introduced in SQL Server 2016. Always we keen like why we cannot apply WHERE condition or any other filter in TRUNCATE Command. TRUNCATE command is faster than delete because it consumes the fewer resources than [&#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%2F2016%2F01%2Fsql-server-2016-introduce-new-truncate-by-partitions-number%2F&amp;linkname=SQL%20Server%202016%3A%20Introduce%20New%20TRUNCATE%20%20by%20Partitions%20Number" 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%2F2016%2F01%2Fsql-server-2016-introduce-new-truncate-by-partitions-number%2F&amp;linkname=SQL%20Server%202016%3A%20Introduce%20New%20TRUNCATE%20%20by%20Partitions%20Number" 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%2F2016%2F01%2Fsql-server-2016-introduce-new-truncate-by-partitions-number%2F&amp;linkname=SQL%20Server%202016%3A%20Introduce%20New%20TRUNCATE%20%20by%20Partitions%20Number" 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%2F2016%2F01%2Fsql-server-2016-introduce-new-truncate-by-partitions-number%2F&amp;linkname=SQL%20Server%202016%3A%20Introduce%20New%20TRUNCATE%20%20by%20Partitions%20Number" 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%2F2016%2F01%2Fsql-server-2016-introduce-new-truncate-by-partitions-number%2F&amp;linkname=SQL%20Server%202016%3A%20Introduce%20New%20TRUNCATE%20%20by%20Partitions%20Number" 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%2F2016%2F01%2Fsql-server-2016-introduce-new-truncate-by-partitions-number%2F&amp;linkname=SQL%20Server%202016%3A%20Introduce%20New%20TRUNCATE%20%20by%20Partitions%20Number" 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%2F2016%2F01%2Fsql-server-2016-introduce-new-truncate-by-partitions-number%2F&#038;title=SQL%20Server%202016%3A%20Introduce%20New%20TRUNCATE%20%20by%20Partitions%20Number" data-a2a-url="https://www.dbrnd.com/2016/01/sql-server-2016-introduce-new-truncate-by-partitions-number/" data-a2a-title="SQL Server 2016: Introduce New TRUNCATE  by Partitions Number"></a></p><p>In this post, I am sharing a new version of TRUNCATE command which used to truncate the partitions and newly introduced in SQL Server 2016.</p>
<p>Always we keen like why we cannot apply WHERE condition or any other filter in TRUNCATE Command. TRUNCATE command is faster than delete because it consumes the fewer resources than DELETE and it is not generating any transaction logs. </p>
<blockquote><p>Now with the SQL Server 2016 you can perform TRUNCATE basis on Partition Number.<br />
If you have a big size of the table and you already applied proper partitions on that table, you can use the new TRUNCATE command for truncating the data. </p></blockquote>
<p><strong>Below is a full demonstration on this:</strong></p>
<p><strong>CREATE SAMPLE DATABASE:</strong></p>
<pre class="crayon-plain-tag">CREATE DATABASE TruncatePartitions
GO</pre> </p>
<p><strong>ADD File Group to New Database:</strong></p>
<pre class="crayon-plain-tag">ALTER DATABASE TruncatePartitions ADD FILEGROUP [2015]
ALTER DATABASE TruncatePartitions ADD FILEGROUP [2016]
GO</pre> </p>
<p><strong>Create .ndf file to store partitions data and attached to perticular filegroup:</strong></p>
<pre class="crayon-plain-tag">ALTER DATABASE TruncatePartitions
  ADD FILE
  (NAME = N'Partitions_2015',
  FILENAME = N'C:\PartitionsData\Partitions_2015.ndf'
  )
  TO FILEGROUP [2015]  

ALTER DATABASE TruncatePartitions
  ADD FILE
  (NAME = N'Partitions_2016',
  FILENAME = N'C:\PartitionsData\Partitions_2016.ndf'
  )
  TO FILEGROUP [2016]
GO</pre> </p>
<p><strong>Create Partition functions:</strong></p>
<pre class="crayon-plain-tag">CREATE PARTITION FUNCTION DateRangeFN(DATETIME)  AS
  RANGE LEFT FOR VALUES
  ('2015-12-31',
  '2016-12-31'
  )
GO</pre> </p>
<p><strong>Create Partition scheme:</strong></p>
<pre class="crayon-plain-tag">CREATE PARTITION SCHEME DateRangeScheme AS
  PARTITION DateRangeFN  TO
  ([2015],
   [2016],
   [PRIMARY]  )
GO</pre> </p>
<p><strong>Create Sample table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_SamplePartitionPartition
(ID INT NOT NULL,
[SampleDate] DATETIME)
ON DateRangeScheme ([SampleDate]);
GO</pre> </p>
<p><strong>Insert Sample data:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_SamplePartition VALUES (1,'2015-08-06')
INSERT INTO tbl_SamplePartition VALUES (2,'2015-05-08')
INSERT INTO tbl_SamplePartition VALUES (3,'2015-04-02')
INSERT INTO tbl_SamplePartition VALUES (4,'2015-06-25')
INSERT INTO tbl_SamplePartition VALUES (5,'2015-09-26')
INSERT INTO tbl_SamplePartition VALUES (6,'2016-02-12')
INSERT INTO tbl_SamplePartition VALUES (7,'2016-08-16')
INSERT INTO tbl_SamplePartition VALUES (8,'2016-04-08')
INSERT INTO tbl_SamplePartition VALUES (9,'2016-09-14')
GO</pre> </p>
<p><strong>Script to check, if the data exist in Partitions:</strong></p><pre class="crayon-plain-tag">SELECT 
	OBJECT_NAME(OBJECT_ID) AS TableName
	, partition_number AS PartitionNumber
	, rows AS TotalRows
FROM sys.partitions
WHERE OBJECT_NAME(OBJECT_ID)='tbl_SamplePartition';
GO</pre><p> </p>
<p><strong>Final step to TRUNCATE Partitions by Partition Number:</strong></p>
<pre class="crayon-plain-tag">TRUNCATE TABLE tbl_Sample WITH (PARTITIONS (1));
GO</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
