473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Partition function - Unknow range column

Hi,

I need to create a partition table but the column on which I need to
create a partition may not have any logical ranges. So while creating
or defining partition function I can not use any range.

like

CREATE PARTITION FUNCTION my_part_func (NUMERIC(7)) AS RANGE LEFT FOR
VALUES (1,100,1000);

Is there any way to define partition function in SQL Server something
like Oracle HASH partitions where logical range is unkown?

Thanks

Sameer

May 4 '06 #1
5 5930
Hi Sameer,

The SQL Script below works to create a partioned updateable view

It Uses these check constraints
CONSTRAINT [check_PartitionColumn1] CHECK (PartitionColumn in (1,100))
CONSTRAINT [check_PartitionColumn2] CHECK (PartitionColumn in (1000,
10000))

But if you change the check constraints to

CONSTRAINT [check_PartitionColumn1] CHECK (PartitionColumn in (1,100,1000))
CONSTRAINT [check_PartitionColumn2] CHECK (PartitionColumn in (2,100,1000))

It won't work becase (according to BOL)

"The key ranges of the CHECK constraints in each table do not overlap with
the ranges of any other table"

Some other things worth noting:

Partitioning columns cannot allow nulls.
Partitioning columns must be a part of the primary key of the table.
Partitioning columns cannot include identity
This works

CREATE TABLE [MyPartionTest1] (
[RowId] [int] NOT NULL ,
[PartitionColumn] int NOT NULL ,
[Data] [varchar] (20) NULL ,
CONSTRAINT [PK_MyPartionTest1] PRIMARY KEY CLUSTERED
(
[RowId],
[PartitionColumn]
) ON [PRIMARY] ,
CONSTRAINT [check_PartitionColumn1] CHECK (PartitionColumn in (1,100))
) ON [PRIMARY]
GO

CREATE TABLE [MyPartionTest2] (
[RowId] [int] NOT NULL ,
[PartitionColumn] int NOT NULL ,
[Data] [varchar] (20) NULL ,
CONSTRAINT [PK_MyPartionTest2] PRIMARY KEY CLUSTERED
(
[RowId],
[PartitionColumn]
) ON [PRIMARY] ,
CONSTRAINT [check_PartitionColumn2] CHECK (PartitionColumn in (1000,
10000))
) ON [PRIMARY]
GO

go

Create View MyPartionTest
as
select * from MyPartionTest1
union all
select * from MyPartionTest2

go

insert MyPartionTest Values(1,1,'Data 1-100')

--
-Dick Christoph
dc******@mn.rr.com
612-724-9282
"sameer_deshpande" <sa**************@hotmail.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
Hi,

I need to create a partition table but the column on which I need to
create a partition may not have any logical ranges. So while creating
or defining partition function I can not use any range.

like

CREATE PARTITION FUNCTION my_part_func (NUMERIC(7)) AS RANGE LEFT FOR
VALUES (1,100,1000);

Is there any way to define partition function in SQL Server something
like Oracle HASH partitions where logical range is unkown?

Thanks

Sameer

May 4 '06 #2
Hi Sammeer,

I just realized I may not may answered your question.

Why are you partitioning these tables? Are they for example separate
companyids where you want to group certain ones on certain tables? Are the
tables distributed on different servers or in different file groups? What
characteristic defines your partitioning logic?

If they are different companies for example you could store a partioncolumn
in a company table and then associate the company_id with a partioncolumn in
a 1 to 1 correspondence (where the parition_id would be in a specific range)

Something like

Company_ID PartionColumn
10 1
100 3
1000 2
10000 4
CONSTRAINT [check_PartitionColumn1] CHECK (PartitionColumn in (1,2))
CONSTRAINT [check_PartitionColumn2] CHECK (PartitionColumn in (3, 4)) -Dick

--
"DickChristoph" <dc********@yahoo.com> wrote in message
news:fF************@tornado.rdc-kc.rr.com... Hi Sameer,

The SQL Script below works to create a partioned updateable view

It Uses these check constraints
CONSTRAINT [check_PartitionColumn1] CHECK (PartitionColumn in (1,100))
CONSTRAINT [check_PartitionColumn2] CHECK (PartitionColumn in (1000,
10000))

But if you change the check constraints to

CONSTRAINT [check_PartitionColumn1] CHECK (PartitionColumn in
(1,100,1000))
CONSTRAINT [check_PartitionColumn2] CHECK (PartitionColumn in
(2,100,1000))

It won't work becase (according to BOL)

"The key ranges of the CHECK constraints in each table do not overlap
with the ranges of any other table"

Some other things worth noting:

Partitioning columns cannot allow nulls.
Partitioning columns must be a part of the primary key of the table.
Partitioning columns cannot include identity
This works

CREATE TABLE [MyPartionTest1] (
[RowId] [int] NOT NULL ,
[PartitionColumn] int NOT NULL ,
[Data] [varchar] (20) NULL ,
CONSTRAINT [PK_MyPartionTest1] PRIMARY KEY CLUSTERED
(
[RowId],
[PartitionColumn]
) ON [PRIMARY] ,
CONSTRAINT [check_PartitionColumn1] CHECK (PartitionColumn in (1,100))
) ON [PRIMARY]
GO

CREATE TABLE [MyPartionTest2] (
[RowId] [int] NOT NULL ,
[PartitionColumn] int NOT NULL ,
[Data] [varchar] (20) NULL ,
CONSTRAINT [PK_MyPartionTest2] PRIMARY KEY CLUSTERED
(
[RowId],
[PartitionColumn]
) ON [PRIMARY] ,
CONSTRAINT [check_PartitionColumn2] CHECK (PartitionColumn in (1000,
10000))
) ON [PRIMARY]
GO

go

Create View MyPartionTest
as
select * from MyPartionTest1
union all
select * from MyPartionTest2

go

insert MyPartionTest Values(1,1,'Data 1-100')

--
-Dick Christoph
dc******@mn.rr.com
612-724-9282
"sameer_deshpande" <sa**************@hotmail.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
Hi,

I need to create a partition table but the column on which I need to
create a partition may not have any logical ranges. So while creating
or defining partition function I can not use any range.

like

CREATE PARTITION FUNCTION my_part_func (NUMERIC(7)) AS RANGE LEFT FOR
VALUES (1,100,1000);

Is there any way to define partition function in SQL Server something
like Oracle HASH partitions where logical range is unkown?

Thanks

Sameer


May 4 '06 #3
Hi Dick,

Bit more info... I have a table where I store different projects
information. The project id generated using a sequence. The max project
Id will be 9999999. For me it will be of no use to partition on
project_id column because there won't be more than 1000 projects.

Now one can say, if there are no more than 1000 project, then why do I
need partitions? The answer is, there are children's attached to this
project. And children's are too many.

So idea was to use something like a HASH function algorithm for
project_id column, which will partition and will spread data to
different partitions.

f.ex: my Oracle script looks like

CREATE TABLE x (id NUMBER; project_id NUMBER(7), child_id NUMBER
)
PARTITION BY HASH (project_id)
(
PARTITION P01,
PARTITION P02,
PARTITION P03);

So here Oracle used HASH algorithm and my data is spread across
different partitions.

I need compatible SQL Server script, which will do so. But to create
partition tables, I need to create partition function, which defines
the RANGE. And in my case I can define range but it wil be of no use.

Sameer

May 4 '06 #4
Hi Sameer

Well then how about creating 5 Partioned tables and set the Check constriant
of the Partition Colum to be 0 to 4

Each each table definition
Table0
CONSTRAINT [check_PartitionColumn0] CHECK (PartitionColumn = 0)
Table1 CONSTRAINT [check_PartitionColumn1] CHECK (PartitionColumn = 1)
Table2 CONSTRAINT [check_PartitionColumn2] CHECK (PartitionColumn = 2)
Table3 CONSTRAINT [check_PartitionColumn3] CHECK (PartitionColumn = 3)
Table4 CONSTRAINT [check_PartitionColumn4] CHECK (PartitionColumn = 4)
Then when you insert into this partioned view insert ProjectID % 5 into the
Partition Column

% is the SQL Server Modulus operator and deliver the integer remainder after
dividing by 5 in this case.

--
-Dick Christoph
"sameer_deshpande" <sa**************@hotmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com... Hi Dick,

Bit more info... I have a table where I store different projects
information. The project id generated using a sequence. The max project
Id will be 9999999. For me it will be of no use to partition on
project_id column because there won't be more than 1000 projects.

Now one can say, if there are no more than 1000 project, then why do I
need partitions? The answer is, there are children's attached to this
project. And children's are too many.

So idea was to use something like a HASH function algorithm for
project_id column, which will partition and will spread data to
different partitions.

f.ex: my Oracle script looks like

CREATE TABLE x (id NUMBER; project_id NUMBER(7), child_id NUMBER
)
PARTITION BY HASH (project_id)
(
PARTITION P01,
PARTITION P02,
PARTITION P03);

So here Oracle used HASH algorithm and my data is spread across
different partitions.

I need compatible SQL Server script, which will do so. But to create
partition tables, I need to create partition function, which defines
the RANGE. And in my case I can define range but it wil be of no use.

Sameer

May 4 '06 #5
Not that easy to change design. The product support 6 diff RDBMS, so
the java code has to be consistent accross all the databases. Wont able
to affort change in the SQL statements depending on RDBMS - hard fact
:-(

May 4 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

41
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of...
10
by: Xah Lee | last post by:
another functional exercise with lists. Here's the perl documentation. I'll post a perl and the translated python version in 48 hours. =pod parti(aList, equalFunc) given a list aList of...
4
by: eavery | last post by:
I can't seem to find a way to do the following: create table part_table ( col1 int, col2 datetime ) on psX (datename(week,col2)) I want to partition based on the week number of a date field....
3
by: nbajrach | last post by:
how to partition on a table if table already exits without any partition. This is what i tried but gave me error SQL> alter table sip add partition by range(si_id) 2 partition p1_si...
8
ADezii
by: ADezii | last post by:
The inspiration for this Tip was an initial reply by one of our resident Experts to a specific Post. In this Post, the User wanted to know how he could calculate the total number of test results...
0
by: Vinod Sadanandan | last post by:
Table Partition Performance analysis ============================================ Collection of Statistics for Cost-Based Optimization/DBMS_STATS vs. ANALYZE The cost-based approach relies on...
0
debasisdas
by: debasisdas | last post by:
SAMPLE CODE TO CREATE SUB PARTITIONS ======================================= RANGE-HASH-9i ------------------------- CREATE TABLE SUBPART ( ID NUMBER(10) PRIMARY KEY, NAME VARCHAR2(20) )
0
debasisdas
by: debasisdas | last post by:
USING PARTITION =================== PARTITION BY RANGE-as per Oracle 8 -------------------------------------- CREATE TABLE RANGEPART ( ID NUMBER(2) PRIMARY KEY, NAME VARCHAR2(20) )
3
by: Justin | last post by:
What is the syntax to overlap partitions? Lets assume I want a year split amount 4 months (3 partitions for a year) and later adding an additional set of partitions for every 6 months. Plus...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.