Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Jakdb
Starting Member
11 Posts |
Posted - 2011-04-01 : 17:16:21
|
| Hi Friends,I want to know,how to add PK on table with data in it. |
|
|
pdx_2188
Starting Member
12 Posts |
Posted - 2011-04-01 : 17:18:55
|
| Which database platform are you using? MySQL? ORACLE? |
 |
|
|
Jakdb
Starting Member
11 Posts |
Posted - 2011-04-01 : 17:26:16
|
| I am on MSSQL server 2008 Standard. |
 |
|
|
pdx_2188
Starting Member
12 Posts |
Posted - 2011-04-01 : 17:39:01
|
| You expand your tables right click on the table you want a PKID for. Create a new column name it PKID(your choice probably easiest) Data Type should be Int do not allow nulls, and then under column properties scroll to Not For Replication and Choose no. This will assign a PKID; however, if you would like to set it up on current data you will want to create a new table and export your current table into it. Then you will want to import this back into the table where you added the PKID. Make sense? |
 |
|
|
Jakdb
Starting Member
11 Posts |
Posted - 2011-04-01 : 17:48:08
|
| Hi,What about this one.. i got it from olbUSE AdventureWorks;GOALTER TABLE Production.TransactionHistoryArchive WITH NOCHECK ADD CONSTRAINT PK_TransactionHistoryArchive_TransactionID PRIMARY KEY CLUSTERED (TransactionID)WITH (FILLFACTOR = 75, ONLINE = ON, PAD_INDEX = ON)GOhttp://msdn.microsoft.com/en-us/library/ms190273(v=SQL.100).aspxcan this be helpfull i am not sure wether this allows to add PK on table with data in it. |
 |
|
|
|
|
|