Solved

partition table when: delete and re-create the cluster index???

Posted on 2014-11-05
5
228 Views
Last Modified: 2014-11-15
i have this database

CREATE DATABASE dbPart ON  PRIMARY
( NAME = 'dbPart', FILENAME = N'c:\SQLDATA\dbPart.mdf' , SIZE = 3072KB , FILEGROWTH = 1024KB )
 LOG ON
( NAME = 'dbPart_log', FILENAME = N'c:\SQLLOG\dbPart_log.ldf' , SIZE = 1024KB , FILEGROWTH = 10%)

--Creación de los FileGroup
USE master
GO
ALTER DATABASE dbPart ADD FILEGROUP PFG01
GO
ALTER DATABASE dbPart ADD FILEGROUP PFG02
GO
ALTER DATABASE dbPart ADD FILEGROUP PFG03
GO
ALTER DATABASE dbPart ADD FILEGROUP PFG04
GO
ALTER DATABASE dbPart ADD FILEGROUP PFG05
GO

--Creación de los DataFile
ALTER DATABASE dbPart ADD FILE
( NAME = N'PDF01', FILENAME = N'C:\SQLDATA\PDF01.ndf' , SIZE = 3072KB , FILEGROWTH = 1024KB ) TO FILEGROUP PFG01
GO
ALTER DATABASE dbPart ADD FILE
( NAME = N'PDF02', FILENAME = N'C:\SQLDATA\PDF02.ndf' , SIZE = 3072KB , FILEGROWTH = 1024KB ) TO FILEGROUP PFG02
GO
ALTER DATABASE dbPart ADD FILE
( NAME = N'PDF03', FILENAME = N'C:\SQLDATA\PDF03.ndf' , SIZE = 3072KB , FILEGROWTH = 1024KB ) TO FILEGROUP PFG03
GO
ALTER DATABASE dbPart ADD FILE
( NAME = N'PDF04', FILENAME = N'C:\SQLDATA\PDF04.ndf' , SIZE = 3072KB , FILEGROWTH = 1024KB ) TO FILEGROUP PFG04
GO
ALTER DATABASE dbPart ADD FILE
( NAME = N'PDF05', FILENAME = N'C:\SQLDATA\PDF05.ndf' , SIZE = 3072KB , FILEGROWTH = 1024KB ) TO FILEGROUP PFG05
GO

--**********************
I think a table with data, I believe the partition function, I create the partition scheme and the table is partitioned automatically, why?
I expected the partition table when: delete and re-create the cluster index

use dbPart
go

CREATE TABLE [dbo].tabla_demo
(  
id int identity primary key,    
c varchar(200) NULL
)

--2
declare @i int
set @i = 1
while @i<=2 -- Luego 1.000.000 filas
begin        
      INSERT INTO dbo.tabla_demo
      SELECT top (50000)      
               replace(cast(NEWID() as varchar(100)), '-','') + REPLICATE('a', 200-32)    
      FROM AdventureWorks.Sales.SalesOrderHeader   CROSS JOIN AdventureWorks.Sales.SalesOrderDetail
      print cast (@i as varchar(100))  
      set @i=@i+1
end

select * from dbo.tabla_demo

--3
CREATE PARTITION FUNCTION pfPartEE (int)
AS RANGE LEFT FOR VALUES (10000, 20000, 30000, 40000)

--4
CREATE PARTITION SCHEME psPartEE
AS PARTITION pfPartEE
TO (pfg01, pfg02, pfg03, pfg04, pfg05)

      SELECT $PARTITION.pfPartEE(id) AS Particion,
      COUNT(*) AS NumeroRegistros FROM tabla_demo
      GROUP BY $PARTITION.pfPartEE(id)
      ORDER BY Particion
0
Comment
Question by:enrique_aeo
  • 2
  • 2
5 Comments
 
LVL 17

Assisted Solution

by:Barry Cunney
Barry Cunney earned 500 total points
Comment Utility
Hi Enrique,
Typically when creating a new table one would specify the partition scheme as part of the 'CREATE TABLE....' statement.
So in your context, something like the following:
CREATE TABLE [dbo].tabla_demo
(  
id int identity primary key,    
c varchar(200) NULL
) ON psPartEE  (id)

Open in new window


Please confirm that your point is that your table was automatically partitioned, even though you did not explicitly specify any partitioning details for the table.
0
 

Author Comment

by:enrique_aeo
Comment Utility
Many thanks for responding:

The scenario is as follows:
1. The table has data from 2005 year
2. You want to partition the table

to do this I believed it eliminated the index cluster and re create the index, then data were to go to their respective partition.
0
 

Author Comment

by:enrique_aeo
Comment Utility
hi Barry

as I can partition a table that already contains data?
0
 
LVL 17

Accepted Solution

by:
Barry Cunney earned 500 total points
Comment Utility
Hi Enrique,
Yes you can partition an existing table by creating an index on the partition scheme.
The following is an example:
CREATE CLUSTERED INDEX IX_table_demo_partitioncol ON dbo.table_demo (partitioncol)
  WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, 
        ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) 
  ON psPartEE(partitioncol)

Open in new window

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now