Primary key generation in Sql server database

  • The script used to generate a primary key :

    USE [DATABASENAME]

    GO

    ALTER TABLE [dbo].[EmpPers] ADD CONSTRAINT [pk_EmpPers] PRIMARY KEY NONCLUSTERED

    (

    [EepEEID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]

    The primary key : 5GSMM20000K0

    Can anyone explain how that primary key is generated.

    Thanks !!

  • That script does not generate a primary key value.

    All is does is create a primary key on an existing table.

  • Check for existing data in the table or check how the data is getting inserted into the table.

    "Keep Trying"

  • hi can you give your problem in brief description

    Raj Acharya

  • metro17 (12/29/2008)


    The script used to generate a primary key :

    USE [DATABASENAME]

    GO

    ALTER TABLE [dbo].[EmpPers] ADD CONSTRAINT [pk_EmpPers] PRIMARY KEY NONCLUSTERED

    (

    [EepEEID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]

    The primary key : 5GSMM20000K0

    Can anyone explain how that primary key is generated.

    Thanks !!

    Can u tell me, exactly what u facing?

    _____________________________________________________________________________________________________________
    Paresh Prajapati
    ➡ +919924626601
    http://paresh-sqldba.blogspot.com/[/url]
    LinkedIn | Tweet Me | FaceBook | Brijj

  • Hi,

    i m also asking same thing

    call me i will explain you that

    Raj Acharya

  • metro17 (12/29/2008)


    The script used to generate a primary key :

    USE [DATABASENAME]

    GO

    ALTER TABLE [dbo].[EmpPers] ADD CONSTRAINT [pk_EmpPers] PRIMARY KEY NONCLUSTERED

    (

    [EepEEID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]

    The primary key : 5GSMM20000K0

    Can anyone explain how that primary key is generated.

    Thanks !!

    Primary Key is generated by creating an Unique Index and setting a Primary Key Constraint on top of it.

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • if you are looking for the script that create '5GSMM20000K0' as your primary key, then that is not the right one. All that does in define the column in your table, you will need to have another look at your db to find the correct script..

  • Data type is char(12) does not allow nulls .

    Eg of a few primary keys...

    3BQWDL0000K0

    3BQWEB0000K0

    3BQWEX0000K0

    Is there any formula behind it that is generating this ? If so how do I find out that formula in Sql sserver management studio which is what i am using

    Thank you

  • metro17 (12/30/2008)


    Data type is char(12) does not allow nulls .

    Eg of a few primary keys...

    3BQWDL0000K0

    3BQWEB0000K0

    3BQWEX0000K0

    Is there any formula behind it that is generating this ? If so how do I find out that formula in Sql sserver management studio which is what i am using

    Thank you

    There sure must be some sort of logic to generate such values but that code snippet you've posted almost certainly does not generate these values. 😉

    You should look for the code that inserts data into that table to find out how things happen.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • hi as per you told that if you want to check for this particular column of primary key then right click on table and click on design and now click on primary key column and check column property is there any default value or formula added into that or not

    Raj Acharya

  • raj acharya (12/31/2008)


    hi as per you told that if you want to check for this particular column of primary key then right click on table and click on design and now click on primary key column and check column property is there any default value or formula added into that or not

    Agreed - that kind of looks like NEWSEQUENTIALID() to me.... check the default value for that column.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply