Creating PK

  • Following is the empdetails table in my organization which has been used for last 3 years.

    create table Empdetails(empid int , empname varchar)

    We noticed that there was no primary key and now we are looking for transactional replication to replicate this data. How can I create primary key on this table. According to my understanding the primary key can be created only when the table is created. Do I need to create a dummy table and then transferring data, rename this table as Empdetails after dropping the original table?

    -Lk

  • luckysql.kinda (2/16/2010)


    Following is the empdetails table in my organization which has been used for last 3 years.

    create table Empdetails(empid int , empname varchar)

    We noticed that there was no primary key and now we are looking for transactional replication to replicate this data. How can I create primary key on this table. According to my understanding the primary key can be created only when the table is created. Do I need to create a dummy table and then transferring data, rename this table as Empdetails after dropping the original table?

    -Lk

    ALTER TABLE Empdetails ADD CONSTRAINT PK_Empdetails PRIMARY KEY ....

    Refer BOL for more information.

  • Check if you have an unique index on empid column...

    if yes then build your PK on it.

    if no then check for and fix empid duplicates then build your PK on 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.

Viewing 3 posts - 1 through 2 (of 2 total)

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