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 |
|
skiabox
Posting Yak Master
169 Posts |
Posted - 2008-01-03 : 06:58:53
|
| Is there any way I can check if the values of a field are unique(so the field is a primary key candidate).Thank you for your time. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-03 : 07:03:16
|
| SELECT COUNT(Field) -Count(Distinct Field) FROM TableThis will be zero if its values are all unique. |
 |
|
|
skiabox
Posting Yak Master
169 Posts |
Posted - 2008-01-03 : 07:26:07
|
| Thnx a lot!Is there a shortcut to find which fields are primary key candidates or should I search one by one with the above query? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-03 : 07:36:28
|
| You need to do this for each field |
 |
|
|
skiabox
Posting Yak Master
169 Posts |
Posted - 2008-01-03 : 07:40:27
|
| Ok!thnx a lot for helping me! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-03 : 07:47:21
|
quote: Originally posted by skiabox Thnx a lot!Is there a shortcut to find which fields are primary key candidates or should I search one by one with the above query?
select * from information_schema.table_constraintswhere table_name='your table' and constraint_type='primary key'MadhivananFailing to plan is Planning to fail |
 |
|
|
skiabox
Posting Yak Master
169 Posts |
Posted - 2008-01-05 : 17:29:13
|
| madhivanan : Can you give a specific example? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-07 : 00:59:00
|
quote: Originally posted by skiabox madhivanan : Can you give a specific example?
What did you understand from the query?Replace your table by actual table usedMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|