Φώτης Μυλωνάς replied to Jay
02-Feb-10 11:13 AM

Hi Jay,
thanks a lot for your answer.
Considering i have primary - foreign key relation in my database, lets say
persons and adresses, what i
would do in life before partitioning, would be to put a primary key on my
primary table "persons" and relate it to table "addresses".
the create statment would be like this:
CREATE TABLE [dbo].[Persons](
[ID] [int] not NULL,
[PersonType] [int] not NULL,
[Name] [nvarchar](50) NULL,
[Surname] [nvarchar](50) NULL
primary key (id)
) ON [primary]
GO
now if i would like to use partitioning ideally i would rewrite it as:
CREATE TABLE [dbo].[Persons](
[ID] [int] not NULL,
[PersonType] [int] not NULL,
[Name] [nvarchar](50) NULL,
[Surname] [nvarchar](50) NULL
primary key (id)
) ON myPartitionScheme(Persontype)
GO
the only problem is that if i do this, im getting the error
Msg 1908, Level 16, State 1, Line 1
Column 'PersonType' is partitioning column of the index
'PK__Persons__239E4DCF'. Partition columns for a unique index must be a
subset of the index key.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
However, if i rewrite it as
CREATE TABLE [dbo].[Persons](
[ID] [int] not NULL,
[PersonType] [int] not NULL,
[Name] [nvarchar](50) NULL,
[Surname] [nvarchar](50) NULL
primary key (id,persontype)
) ON myPartitionScheme(Persontype)
GO
including the partition column in the primary key, then its perfectly ok.
however, this leads to altering all foregin key tables for to include there
the partition column as well and somehow it violates the uniqness of the
primary key i used to have, since now uniqness is dependant on two columns
instead of the one i always used.
so here is where i would like to ask how can i marry the primary key best
practice i used to know so far, with the concept of partitioning on another
column other than the primary key i used to have.
thanks again,
Fotis