Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

need help with table design - opinions please

 
   Database Help (Home) -> Programming RSS
Next:  Full-text indexing and underscores  
Author Message
Derek

External


Since: Mar 14, 2007
Posts: 32



(Msg. 1) Posted: Thu Dec 21, 2006 7:14 am
Post subject: need help with table design - opinions please
Archived from groups: microsoft>public>sqlserver>programming (more info?)

i have a table called ORDERQUEUE laid out like this

create table [ORDERQUEUE] (oq_id int identity primary key, customer_id
int not null, grouping_id int null, queue_date datetime not null
default getdate().... other columns here)

clustered index is grouping_id/queue_date
the primary key is not clustered

the grouping_id is used group together related rows for processing. a
stored procedure gets the next sequence id and updates those records
for a customer where the grouping_id = null.

if another process comes along and runs the same procedure i don't want
it to update the same rows for a customer with a different grouping id.


I use set rowcount to keep the number of updates low. if the next batch
gets a different grouping id then that is ok. i order by the queue date
to get the early rows first.

i added a serializable hint to keep readers from getting the rows after
the insert into the #queue table.

/* order by the queue_date so we don't process the same rows next time
*/
set rowcount 10000

insert into #queue (oq_id, customer_id, grouping_id, queue_date)
select oq_id, customer_id, grouping_id, queue_date from order_queue
(serializable)
where customer_id = @customer_id and grouping_id is null
order by queue_date

set rowcount 0

update q
set grouping_id = @new_grouping_id
from order_queue oq inner join #queue q on q.oq_id = oq.oq_id

commit

by setting serializable on the table during the select i can hold onto
the rows while they are
being updated and then release them. i expect another execution of the
stored procedure for that customer will block but execution for any
other customer will go through.

also, since the grouping_id is part of the clustered index but can be
null can the optimizer still use it?

any opinions or suggestions?



thanks
derek foley

 >> Stay informed about: need help with table design - opinions please 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Opinions on Cascading Delete/Update - I'm just wondering if folks with lots of SQL Server experience tend to rely on cascading deletes and updates, or if there are reasons why it makes sense to write code to delete things in the proper order. So far, I'm not using cascading deletes and..

Looking for Opinions on Repeated Dataload Requirement - I am working on a project that has an integrated controller that dumps data out from some machinery every minute from the hours of 8am-8pm. The data is written to a CSV file, and then uploaded automatically to an FTP server every 20 minutes. I am..

Request for opinions on the INCLUDE() use in an index - Given this test table which is planned to contain between 50K and 200K rows; CREATE TABLE Car ( AccountNo int NOT NULL, -- clustered PK VIN varchar(32) NOT NULL, Leased bit NOT NULL ) I will need to do these..

table design help - hey all, salary table ------------- salary date, Salary employment history table ----------------------------- job title, employment date let's say i want to pick a record in the history table and find out what salary they were making at the time....

Suitable Table Design ? - Hello David, Would (contract_num,details_changed_date) key be efficient in Queries or (contract_num,AmendId) key be efficient in Queries - Note that AmendId is a sequence number for each of the amendments. Gopi "David Portas"..
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]