0

I configure identity column with composite primary key on Transactional Replication scenario to maintain unique row value.

    CREATE TABLE [dbo].[AD_CLIENT_DETAIL_MST](
    [CLIENT_ID] [bigint] IDENTITY(1,1) NOT NULL,
    [SERVER_ID] [char](1) NOT NULL CONSTRAINT   [DF_AD_CLIENT_DETAIL_MST_SERVER_ID]  DEFAULT ('A'),
    [C_NAME] [varchar](300) NOT NULL,
    [CLIENT_TITLE] [varchar](10) NULL,
    [C_FIRST_NAME] [varchar](100) NOT NULL,
    [C_MIDDLE_NAME] [varchar](100) NULL,
    [C_LAST_NAME] [varchar](100) NULL,
    [C_DOB] [date] NULL,
    [RESELLER_ID] [bigint] NOT NULL,
    [RESELLER_NAME] [varchar](300) NULL,
    [CITY] [varchar](50) NULL,
    [STATE] [varchar](50) NULL,
    [COUNTRY] [varchar](50) NULL,
    [COMPANY_NAME] [varchar](500) NULL,
    [COMPANY_LOGO_PATH] [nvarchar](max) NULL,
    [COM_ADD1] [varchar](300) NULL,
    [COM_ADD2] [varchar](300) NULL,
    [BANK_NAME] [varchar](50) NULL,
    [BANK_ACCOUNT_NO] [varchar](50) NULL,
    [PAN_NO] [varchar](20) NULL,
    [TIN_NO] [varchar](20) NULL,
    [BANNER] [varchar](50) NULL,
    [YOCC_NO] [varchar](15) NOT NULL,
    [PRIMARY_NO] [varchar](15) NOT NULL,
    [SECONDARY_NO] [varchar](15) NULL,
    [ALLOWED_CHANNEL] [int] NOT NULL,
    [ACTIVE_OPERATOR] [int] NOT NULL,
    [CALL_ROUTING_TYPE] [bigint] NOT NULL,
    [CALL_ROUTING_PATTERN] [bigint] NOT NULL CONSTRAINT [DF_AD_CLIENT_DETAIL_MST_CALL_ROUTING_PATTERN]  DEFAULT ((0)),
    [LIST_STATUS] [bigint] NOT NULL,
    [SMS_PROVIDER_ID] [bigint] NOT NULL,
    [EMAIL_PROVIDER_ID] [bigint] NULL,
    [IS_BLOCK] [bit] NOT NULL,
    [REG_DATE] [datetime] NOT NULL,
    [TOTAL_USER] [int] NULL,
    [TOTAL_ADMIN] [int] NULL,
    [EXP_DATE] [datetime] NULL,
    [CHANNEL_COUNTER] [int] NULL,
 CONSTRAINT [PK_AD_CLIENT_DETAIL_MST] PRIMARY KEY CLUSTERED 
(
    [CLIENT_ID] ASC,
    [SERVER_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

So, when i define two primary key then i will give some slow query performance or not ?

2
  • What do you mean by "define two primary key" and which queries do you think would be slowed down?
    – Tom V
    Commented Aug 7, 2016 at 5:37
  • I Define Composite Primary Key because of my scenario is Transactional Replication with AlwaysOn Subscriber and i have multiple Publisher which is synch data to AlwaysOn Subscribers.To avoid conflict issue of identity column at subscriber box ,i created composite primary key. Commented Aug 9, 2016 at 7:54

1 Answer 1

2

Performance not only depends on the query, but also the kind of data you store in the table.

Let's zoom out and talk about how you choose a clustering key for a table. Generally, you want the clustering keys to be:

  • Static - non-changing
  • Unique
  • Narrow - as few fields as possible, with as small datatypes as practical
  • Ever-increasing - which gives you a hotspot at the end of the table, which would sound bad but is usually good in small (sub-terabyte) database designs

Here, you've already got a single field that satisfies all of those requests: CLIENT_ID, which you defined as an identity field. You could just start by using that field alone - adding SERVER_ID doesn't really buy you anything.

However, I'm a little suspicious of the table design because SERVER_ID is only a CHAR(1). That gives you a limited number of servers to work with per CLIENT_ID. I don't know what you're trying to model, but generally an ID wouldn't be a single character.

5
  • I am configuring transactional Replication with AlwaysOn subscriber.currently we have only two publisher(in future max server is 8-9) this is the reason i am using server_id char(1).suggest me another option to maintain identity column. Commented Aug 9, 2016 at 7:13
  • Also my some of master table is read only mode at publisher side.and this table is write mode at AlwaysOn subscriber box. Commented Aug 9, 2016 at 7:25
  • Publisher box 1 and 2 is also subscribe master table from AlwaysOn primary box as publisher. Commented Aug 9, 2016 at 7:31
  • I Define Composite Primary Key because of my scenario is Transactional Replication with AlwaysOn Subscriber and i have multiple Publisher which is synch data to AlwaysOn Subscribers.To avoid conflict issue of identity column at subscriber box ,i created composite primary key. Commented Aug 9, 2016 at 7:56
  • You'll want to pick up a book on replication. There's lots of techniques using identity seeds - for example, start one server at positive 1, and the other server at negative one.
    – Brent Ozar
    Commented Aug 9, 2016 at 11:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.