views:

354

answers:

2

In SQL its possible to have fields that cannot contain duplicate data.

How is this possible in SharePoint?

Lets say you have a list containing values like

ORANGES
APPLES 
PEARS

How do you ensure that the user cannot enter

ORANGES
APPLES 
PEARS
ORANGES

Thanks

+1  A: 

This can't be done out of the box. But there are these community solutions:

Alex Angas
Alex Angas
Ah - thats typical of JokePoint err I mean SharePoint, I would be dissappointed if it didn't fail me each and every time. Thank you though for your answer.
JL
Grrr - and SO's auto hyperlinking doesn't work. Search on the web and you will find his article! http://www.google.co.uk/search?q=unique+site%3Ashillier.com
Alex Angas
@JL: Completely understand your frustrations. Note that the 2007 version is almost 3 years old and has come a long way since the previous SPS 2003 bringing a huge number of features. The fact that it is so extensible and devs like us can create these solutions that significantly improve it is a credit to the product's design.
Alex Angas
Alex - do you think MOSS 2010 will have constraints?
JL
@JL: There's been nothing mentioned publicly about this so it's too early to say. SharePoint 2010 will make life easier for developers however, see http://sharepoint.microsoft.com/2010/Sneak_Peek/Pages/Developer-Video.aspx
Alex Angas
@Alex Please read the other answer....
JL
A: 

Alex thanks for your answer man - don't take this the wrong way - but before you say - "t is a credit to the product's design"

Think of this scenario...

Lets say you had 1 million records....

And you needed to check for unique constraints....

IN SQL or MySQL or Oracle, this would happen in around 0.001ms. IN MOSS - this would take over 1 minute, I think possible 2-3 minutes (this is because you need to manually loop through all the items in the list using an SPListCollection).

So now consider if you wanted to insert 1000 more records into a table already containing 1 million records....

In SQL or MySQL or Oracle - this would take less than 1.5 seconds.... In MOSS lets do the maths:

1 item = 2-3 minutes x 1000 = 2000-3000 minutes... lets just make that 2500 minutes = 41hours....

You can't keep a straight face , and tell me SharePoint has good design...

JL
To check for the unique constraint you don't actually need to loop through all the items, you can try out SPQuery, I am sure that SPQuery will do it in a Performance friendly way, so as not to compare each and every item. Ultimately all the list items are in the SQL so SPQuery should tuned to make use of it.
Kusek
SharePoint isn't designed to be a nice UI to SQL Server ;-) It's doing much more with more complexity behind the scenes (although I'm pretty sure its database design could be significantly improved). Don't view it as the saviour for any business problem as this simply isn't the case. It's often incorrectly marketed this way but a proper business requirements analysis should be done before mindlessly going with it.
Alex Angas
Having said that, management often make these decisions due to being ill-informed or being sold on the marketing buzz. Then it's down to people like you and me to implement the solution ;-)
Alex Angas