Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-11-05
5
Medium Priority
?
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 17

Assisted Solution

by:Barry Cunney
Barry Cunney earned 2000 total points
ID: 40425740
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
ID: 40425960
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
ID: 40429626
hi Barry

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

Accepted Solution

by:
Barry Cunney earned 2000 total points
ID: 40433153
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

688 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