Solved

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

Posted on 2014-11-05
5
247 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 500 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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
View SQL database for NPS accounting 4 20
store vs query adhoc - no show rows 4 37
SQL State HYT00. Timeout expired proplem 8 44
SQL Job Failed 6 31
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
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…

739 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