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 |
mikeallenbrown
Yak Posting Veteran
72 Posts |
Posted - 2013-06-19 : 10:01:05
|
I'm still a novice with SQL so bear with me...I have a row labeled 'MRNum_ClientID' computed as ([MRNum]+CONVERT([varchar],[ClientID],(0))).I was on another forum discussing how I could make it so my users couldn't enter in a duplicate record in myprogram I've created in Alhpa Five. It was suggested to "make an index" and then SQL would return an error. How do I go about doing this? In my program the user types in the MRNum (medical record number) and ClientID is automatically populated.Bottom line is 'MRNum_ClientID' must always be unique.Thank you for your help.-MikeMike Brown |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-06-19 : 10:17:20
|
quote: Originally posted by mikeallenbrown In my program the user types in the MRNum (medical record number) and ClientID is automatically populated.Bottom line is 'MRNum_ClientID' must always be unique.-MikeMike Brown
Create a non clustered "unique" index on the combination of these two fieldsCheersMIK |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-06-19 : 10:19:41
|
e.g. create unique nonclusetered index index_NameOn TableName(MRNum,ClientID)CheersMIK |
|
|
mikeallenbrown
Yak Posting Veteran
72 Posts |
Posted - 2013-06-19 : 11:20:38
|
Thank you! ... but now I'm getting errors because there are existing duplicates in my table already (so it cancels). My follow question would be how can I display a list of all the duplicates? ...and edit them of course.-MikeMike Brown |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-06-19 : 11:35:46
|
Following query will give you the repeating/duplicates MRNNum and ClientID SELECT MRNNum,ClientID,Count(1) FROM TableNameGroup by MRNNum,ClientIDHaving count(1) >1CheersMIK |
|
|
mikeallenbrown
Yak Posting Veteran
72 Posts |
Posted - 2013-06-19 : 11:54:46
|
Thank you again!-MikeMike Brown |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-06-19 : 11:59:32
|
You're welcomeCheersMIK |
|
|
|
|
|