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 |
|
mavericky
Posting Yak Master
117 Posts |
Posted - 2011-11-08 : 18:22:51
|
| Hi,I have a table with the fields:StartTimeTypeZoneKWhand data-StartTime Zone Type KWh2011-09-01 00:15:00.000 MVEC A 5305.09572011-09-01 00:30:00.000 MVEC A 5067.29390I have 100 rows with different Zone values.I want to make Zone and StartTime as PrimaryKeys by sql code. Can it be done, even though i already inserted all data?Thanks,Mavericky |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-11-08 : 18:32:29
|
| Sure.ALTER TABLE <table name> ADD CONSTRAINT <constraint name> PRIMARY KEY (<column names>)--Gail ShawSQL Server MVP |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-09 : 01:05:51
|
| one thing to note is because you already have data, there should not any duplicate combination of zone,startime present else pk will fail. so check for and remove duplicates before applying the pk------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|