dbTalk Databases Forums  

Should I split the record?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Should I split the record? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
andrew
 
Posts: n/a

Default Should I split the record? - 03-26-2011 , 07:59 PM






Hello all,

This is a newbie design question. I have a table with the following fields

TABLE A
ID, Prop1, Prop2

I expect that I might have multiple concurrent users accessing the same
record (in a recordset via SELECT). If I expect to have users modify either
Prop1 or (XOR) Prop2 I should also expect the DB to complain since one of
the users would have the record locked (I'm learning lots about locks).
Would that complaint be an ADO exception or would the locked out user just
wait for the record to be free? Would a better design for this scenario be

TABLE A
ID, Prop1

TABLE B
ID, Prop2

this way the users would not interfere?

Thanks

Reply With Quote
  #2  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Should I split the record? - 03-26-2011 , 08:55 PM






andrew wrote:
Quote:
Hello all,

This is a newbie design question. I have a table with the following
fields
TABLE A
ID, Prop1, Prop2

I expect that I might have multiple concurrent users accessing the
same record (in a recordset via SELECT). If I expect to have users
modify either Prop1 or (XOR) Prop2 I should also expect the DB to
complain since one of the users would have the record locked (I'm
learning lots about locks). Would that complaint be an ADO exception
or would the locked out user just wait for the record to be free?
It depends - if you are using a cursor to do the update, whether you open it
with optimistic or pessimistic locking will be the determining factor. If
you are not useing cursors (rcordsets) to perform the updates, then the
database will control the transactions so that the first one will be done,
followed by the second.

Quote:
Would a better design for this scenario be
TABLE A
ID, Prop1

TABLE B
ID, Prop2

this way the users would not interfere?

No, the best design would be a single table with ID, PropType (1 or 2) and
Prop. Data (the "1" and "2") should be stored as data (in rows) not in
metadata (table.column names)

Reply With Quote
  #3  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Should I split the record? - 03-27-2011 , 06:31 AM



andrew (thegroup (AT) microsoft (DOT) com) writes:
Quote:
This is a newbie design question. I have a table with the following
fields

TABLE A
ID, Prop1, Prop2

I expect that I might have multiple concurrent users accessing the same
record (in a recordset via SELECT). If I expect to have users modify
either Prop1 or (XOR) Prop2 I should also expect the DB to complain
since one of the users would have the record locked (I'm learning lots
about locks).
This all depends on you implement the application. If you update only the
colunm that the user actually has changed, both changes will have effect.

Commonly, you update all columns, changed or not, and in this case one
change will overwrite another. There are mechanisms to prevent this from
happening, for instance timestamp columns. Or simply compare all columns
with the saved values which is what some client APIs do if you hand over the
responsibility to them, rather than crafting the UPDATE statements yourself.

As for the table design, it is impossible to say what is the best, as a good
database design is governed by several factors. In fact, I would say that
the particular problem you have presented carries very little weight. This
situations may be better handled in the application to permit concurrent
updates. But again, from your abstract description, it is impossible to
give an answer in either direction.

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
  #4  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Should I split the record? - 03-27-2011 , 08:34 PM



andrew wrote:
Quote:
Hello all,

This is a newbie design question. I have a table with the following
fields
TABLE A
ID, Prop1, Prop2

I expect that I might have multiple concurrent users accessing the
same record (in a recordset via SELECT). If I expect to have users
modify either Prop1 or (XOR) Prop2 I should also expect the DB to
complain since one of the users would have the record locked (I'm
learning lots about locks). Would that complaint be an ADO exception
or would the locked out user just wait for the record to be free? Would a
better design for this scenario be
TABLE A
ID, Prop1

TABLE B
ID, Prop2

this way the users would not interfere?

My answer is based on the assumption that Prop1 and Prop2 are "repeating"
attributes, i.e., multiple instances of the same type of property (same
datatype, etc.) If that's not the case, then my answer does not apply.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.