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 |
|
herbjorn
Starting Member
8 Posts |
Posted - 2005-04-14 : 08:30:34
|
| Hi,I need to make sure that duplicate values doesn't get inserted into a table. The duplicate value is rather a pair of values.Type Name1 Green2 Green * Not duplicate values3 Green * Duplicate valuesHow can I do this? I'm thinking about having a stored procedure for insert and checking that the value doesn't exist and then directly do the insert:IF NOT EXISTS(SELECT * FROM Table WHERE Type=1 AND Name=Green) INSERTWill this be enough? Can another insert happen between my SELECT and the INSERT? If so How do I do?sincerely Herbjörn |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-04-14 : 08:56:00
|
that's ok... you can also put constraints on the columns you want unique.i'd say it's very unlikely that it does. how many user inserts per second do you ecpect???Go with the flow & have fun! Else fight the flow |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2005-04-14 : 10:20:29
|
| I'd say it's highly unlikely if not impossible that anything will be inserted between the two statements but to make sure you can put an explicit transaction around it:BEGIN TRANIF NOT EXISTS(SELECT * FROM Table WHERE Type=1 AND Name=Green)INSERTCOMMIT TRAN--Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2005-04-14 : 11:33:22
|
| Lumbago, that is one of the best signature quotes I've seen in a long time.Mike"oh, that monkey is going to pay" |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2005-04-14 : 11:56:27
|
Thanx --Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
|
|
|
|