Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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…

808 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