Solved

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

Posted on 2014-11-05
5
256 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

635 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