<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'columnstore', 'SQL Server 2012', and 'indexes'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=columnstore,SQL+Server+2012,indexes&amp;orTags=0</link><description>Search results matching tags 'columnstore', 'SQL Server 2012', and 'indexes'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Geek City: Build a Big Table with a Columnstore Index</title><link>http://sqlblog.com/blogs/kalen_delaney/archive/2012/04/26/Build-a-Big-Table-with-a-Columnstore-Index.aspx</link><pubDate>Thu, 26 Apr 2012 18:18:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43013</guid><dc:creator>Kalen Delaney</dc:creator><description>&lt;p&gt;I was looking all over to find a big table to use for my columnstore 
examples in my SQL Server 2012 book, and the only one I found was from someone 
at Microsoft and was not publicly available.  When I demonstrate code in my 
writings, I like to have the code available for anyone to use, so that was no 
use. &lt;/p&gt;
&lt;p&gt;Finally I realized I was just going to have to do it myself. I actually based 
the script on some work by the awesome Benjamin Nevarez (&lt;a href="http://www.benjaminnevarez.com/"&gt;blog&lt;/a&gt;| &lt;a href="http://twitter.com/BenjaminNevarez"&gt;twitter&lt;/a&gt;), but I needed to make a 
couple of changes to the table structure, and then the loop for adding the data 
took some tweeking to make sure that uniqueness was possible, in case you need 
to test out how the metadata changes when a columnstore index is built on a 
table with a unique clustered index compared to a nonunique clustered index 
compared to a heap. &lt;/p&gt;
&lt;p&gt;I have just finished the chapter on indexes, and decided to make this script 
available. The initial table data is based on the data in Microsoft 
AdventureWorksDW2012 sample database that you can download &lt;a href="http://msftdbprodsamples.codeplex.com/releases/view/55330"&gt;here&lt;/a&gt;.  
(Note that the DW version is the first one under “Other Available Downloads”’; 
it’s not the one under “Recommended Download”. )&lt;/p&gt;
&lt;p&gt;Here is the section of the script that populates most of the 
&lt;em&gt;FactInternetSalesBIG&lt;/em&gt; table. (The original 60K rows were just copied 
from the original &lt;em&gt;FactInternetSales&lt;/em&gt; table. Note that all the statements 
have to be run in a single batch because the local variable’s scope is the 
batch, and because the GO 9 applies to the single batch that precedes it. Of 
course, you can change the number of iterations to end up with a different size 
table. Mine ends up at just over 30 million rows.  In addition to modifying the 
&lt;em&gt;SalesOrderNumber&lt;/em&gt; value on each iteration, I also changed the value of the 
Revision column to indicate which pass through the insert loop was being 
executed. &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;br&gt;&lt;font size="2" face="Courier New"&gt;&lt;br&gt;-- Copy the new big table into itself 
9 times&lt;br&gt;DECLARE @RevisionNumber nchar(2);&lt;br&gt;SELECT @RevisionNumber = 
RevisionNumber + 1 FROM RevisionNumberValue;&lt;br&gt;SELECT @RevisionNumber as 
RevisionNumber;&lt;br&gt;INSERT INTO dbo.FactInternetSalesBig WITH (TABLOCK)&lt;br&gt;    
SELECT ProductKey&lt;br&gt;      ,OrderDateKey&lt;br&gt;      ,DueDateKey&lt;br&gt;      
,ShipDateKey&lt;br&gt;      ,CustomerKey&lt;br&gt;      ,PromotionKey&lt;br&gt;      
,CurrencyKey&lt;br&gt;      ,SalesTerritoryKey&lt;br&gt;      ,SalesOrderNumber + 
@RevisionNumber&lt;br&gt;      ,SalesOrderLineNumber&lt;br&gt;      
,@RevisionNumber&lt;br&gt;      ,OrderQuantity&lt;br&gt;      ,UnitPrice&lt;br&gt;      
,ExtendedAmount&lt;br&gt;      ,UnitPriceDiscountPct&lt;br&gt;      ,DiscountAmount&lt;br&gt;      
,ProductStandardCost&lt;br&gt;      ,TotalProductCost&lt;br&gt;      ,SalesAmount&lt;br&gt;      
,TaxAmt&lt;br&gt;      ,Freight&lt;br&gt;      ,CarrierTrackingNumber&lt;br&gt;      
,CustomerPONumber &lt;br&gt;      ,OrderDate&lt;br&gt;      ,DueDate&lt;br&gt;      ,ShipDate&lt;br&gt;  
FROM dbo.FactInternetSalesBig;&lt;br&gt;  UPDATE RevisionNumberValue SET 
RevisionNumber = RevisionNumber + 1;&lt;br&gt;GO 9&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Make sure you have enough log space. My log grew from 1GB to just over 8GB 
when running the script to build the 30 million row table and columnstore index, 
with no clustered index.  &lt;/p&gt;
&lt;p&gt;The downloadable script has commented options to build either a clustered or  
nonclustered index before you build the columnstore index. I suggest building 
the clustered index before the columnstore index,  because building the 
clustered index&amp;nbsp;will rebuild any existing nonclustered indexes, including my 
columnstore index. Building the columnstore index can take a while, on my system 
it was about 10 minutes. (Building the original 30+ million row table took even longer.)&lt;/p&gt;&lt;p&gt;After I finish the chapter on partitioning, I'll have a script to partition this table, but feel free to do that yourself!&lt;/p&gt;
&lt;p&gt;Have fun!&lt;/p&gt;
&lt;p&gt;&lt;font color="#d16349" size="4"&gt;~Kalen&lt;/font&gt;&lt;/p&gt;</description></item></channel></rss>