473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

preventing duplicate row insertion from asp.net app

Data is stored in SQL Server 2000. One table is Person another Item.
Each row in the Person table may have associated with it several rows
in the Item table. The Item table has a field called 'type'. Business
rule: for certain values of this field, at most one row may exist (per
Person) in the Item table.

The DB is accessed from an ASP.NET app and more than one user may try
to insert an Item of the same type (and for the same Person) at the
same type. It would be very easy to ensure the above business rule
using a trigger (on the Item table) or a stored procedure that would
do inside something like this:
IF (NOT EXISTS (SELECT ... FROM Item)) INSERT INTO Item...

Please note that, because of internal coding standards, I cannot
modify the DB and I cannot access the database from my app through
direct SQL statements (e.g., like the one above). I can only access
the Item table through stored procedures that perform inside them
simple selects and inserts on the table.

Assuming the stored procedures (for SELECT and INSERT on the Item
table) are called inside the same method, is there a way to satisfy
the above mentioned business rule (ensure mutual exclusion) at the app
level? Would specifying the isolation level as serializable at the app
level work? Is there a better solution?

Thank you,
Alex
Nov 17 '05 #1
2 1856
Jerry,
Unortunately, I might not be able to modify the DB. (Besides, I do not
see how the SPECIFIED business rule would be enforced through a
primary key.)
I would still need to know if there is a way to enforce the business
rule at the app level.

Thanks,
Alex
"Jerry III" <je******@hotmail.com> wrote in message news:<#b*************@TK2MSFTNGP12.phx.gbl>...
The only good way to do this is using a primary key on the table. Trying to
enforce data consistency in the application layer is not a good idea and
will generally not work (because sooner or later someone will forget to do
so, intentionally or not).

Jerry

Nov 17 '05 #2
You can have a primary key spanning more than one column (which would be the
case of your specific rule).

And yes, there is a way, you will simply check if the value exists before
you try to insert it. There are multiple ways to do that and none will be
100% fool proof, if you forget to do it once (or someone else working with
the same data forgets to do it) or don't do it correctly (with regards to
multiple requests executing simultaneously) you will end up with data that
are "corrupted" based on your rules. You can do that checking with triggers,
stored procedures, or plain SQL, it's entirely up to you...

Jerry

<ab********@yahoo.com> wrote in message
news:34**************************@posting.google.c om...
Jerry,
Unortunately, I might not be able to modify the DB. (Besides, I do not
see how the SPECIFIED business rule would be enforced through a
primary key.)
I would still need to know if there is a way to enforce the business
rule at the app level.

Thanks,
Alex
"Jerry III" <je******@hotmail.com> wrote in message

news:<#b*************@TK2MSFTNGP12.phx.gbl>...
The only good way to do this is using a primary key on the table. Trying to enforce data consistency in the application layer is not a good idea and
will generally not work (because sooner or later someone will forget to do so, intentionally or not).

Jerry

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Raju V.K | last post by:
I am developing a PHP-mysql database. It is noted that when the browser window is refreshed the data is inserted again in the database. unfortunately there is no unique keys that I can use to...
18
by: Elroyskimms | last post by:
I have a table using an identity column as its Primary Key and two columns (table reduced for simplicity) EmployeeNumber and ArrivalTime. CREATE TABLE ( IDENTITY (1, 1) NOT NULL , (10)...
6
by: nick4soup | last post by:
I have read the CGI FAQ 'How can I avoid users hitting "submit" twice' (on http://www.htmlhelp.org/faq/cgifaq.3.html#19 ) which essentially says you have to detect it at the server, using a...
11
by: Jean-Christian Imbeault | last post by:
I have a table with a primary field and a few other fields. What is the fastest way to do an insert into that table assuming that sometimes I might try to insert a record with a duplicate primary...
6
by: planetthoughtful | last post by:
Hi All, I have a C# ASP.NET page that submits back to itself to insert details from a form into a database table. When / if the user refreshes the page (and gets the standard warning that POST...
8
by: mindwarp | last post by:
Hi, When a user submits / posts data my php script Inserts data into my database. If they refresh the script or click back and click submit again I get duplicate record. Is there an easy...
6
by: Oleg Konovalov | last post by:
Hi, I have a Java/JavaScript GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and...
0
by: =?Utf-8?B?SGF3aw==?= | last post by:
Hello, I have the need to verifiy a field in a gridview for a duplicate value against a database before the update takes place. I was thinking that the gridview1.rowupdating would be a good place...
6
by: reppisch | last post by:
Hi Ng, I have a multiset for keeping elements sorted in a container but key values may also be equal. Is there any guaranteed traversal order within the duplicate keys of a multimap? When...
7
by: chowdary | last post by:
I am developing a PHP-mysql database. It is noted that when the browser window is refreshed the data is inserted again in the database. unfortunately there is no unique keys that I can use to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.