Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Creating PK Expand / Collapse
Author
Message
Posted Tuesday, February 16, 2010 2:08 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, May 23, 2013 10:41 PM
Points: 310, Visits: 649
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
Post #865903
Posted Tuesday, February 16, 2010 5:10 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 2:19 AM
Points: 1,101, Visits: 5,271
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.
Post #865990
Posted Tuesday, February 16, 2010 5:26 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,068, Visits: 4,639
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.
Post #866005
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse