Click here to Skip to main content
15,892,298 members
Home / Discussions / Database
   

Database

 
Questionhelp................! Pin
podolski23-Dec-08 15:39
podolski23-Dec-08 15:39 
AnswerRe: help................! Pin
Paddy Boyd23-Dec-08 22:20
Paddy Boyd23-Dec-08 22:20 
QuestionSybase AutoNumber/Identity Column Resetting Pin
mobius11100123-Dec-08 8:28
mobius11100123-Dec-08 8:28 
AnswerRe: Sybase AutoNumber/Identity Column Resetting Pin
Wendelius23-Dec-08 8:44
mentorWendelius23-Dec-08 8:44 
Questionformat date [modified] Pin
cbe_pav23-Dec-08 1:26
cbe_pav23-Dec-08 1:26 
AnswerRe: format date Pin
Syed Mehroz Alam23-Dec-08 20:52
Syed Mehroz Alam23-Dec-08 20:52 
GeneralRe: format date Pin
cbe_pav23-Dec-08 23:59
cbe_pav23-Dec-08 23:59 
QuestionQuery Optimization Pin
ruanr23-Dec-08 0:30
ruanr23-Dec-08 0:30 
Hi all..

To keep it short - We automatically update a set of tables (lets call it the DATA tables) in a client's database by dumping the raw data into a table (DUMP table) which has in INSERT trigger on it, which will then go and update the various data tables. I'm extending this functionality by adding a SETTING table which will allow clients to specify which fields they want updated. The SETTING table has two fields, an ID for each field in the DATA tables, and a setting field, which can be 0 for never update, 1 for always update, and 2 for only update if the corresponding field is null in the data table.

Some people might complain that this is horrible design - There are reasons for it.

My problem lies with optimization of this query. I get 30000 rows (bout 30-40 columns) at a time in the dump table and the trigger runs for about 40 minutes if it updates blindly, but now I need two extra SELECTs per field - first to check the update setting, then to check if the value is NULL should the setting be 2. So this comes down to more or less (ignore syntax trivialities):

<br />
SELECT @setting = UpdateSetting FROM Setting WHERE ID = @fieldid<br />
IF @setting = 1 OR (@setting = 2 AND IS NULL (SELECT field FROM Data WHERE id = @rowID)<br />
  UPDATE Data SET Field = @newfieldval WHERE ID = @rowID<br />

Obviously this query will take AGES to complete, compared to the previous:
<br />
UPDATE Data SET field1 = @newField1Val, <br />
                field2 = @newField2Val,<br />
                [etc]<br />
                ...<br />
       WHERE id = @rowID<br />


How should I go about optimising this? I am still somewhat novice when it comes to SQL. So far I'm considering building up an update string per row, which should at least cut down the number of updates significantly, but the number of extra selects are still a problem. Ideas? Clarifications needed?

Thanks in advance.
AnswerRe: Query Optimization Pin
Paddy Boyd23-Dec-08 0:52
Paddy Boyd23-Dec-08 0:52 
AnswerRe: Query Optimization Pin
Wendelius23-Dec-08 3:18
mentorWendelius23-Dec-08 3:18 
QuestionInsert/Update command with Case in sql server Pin
Uma Kameswari22-Dec-08 22:28
Uma Kameswari22-Dec-08 22:28 
AnswerRe: Insert/Update command with Case in sql server Pin
Wendelius23-Dec-08 3:19
mentorWendelius23-Dec-08 3:19 
QuestionWill MS SQL 2008 recongize an xsd that uses "include"? Pin
CodeBase2522-Dec-08 7:23
CodeBase2522-Dec-08 7:23 
GeneralSql Server Integration Services book recommendation [modified] Pin
givi_s22-Dec-08 3:02
givi_s22-Dec-08 3:02 
GeneralRe: Sql Server Integration Services book recommendation Pin
Abhijit Jana22-Dec-08 3:11
professionalAbhijit Jana22-Dec-08 3:11 
GeneralRe: Sql Server Integration Services book recommendation Pin
Mycroft Holmes22-Dec-08 14:07
professionalMycroft Holmes22-Dec-08 14:07 
QuestionOleDb? Pin
dec8222-Dec-08 1:45
dec8222-Dec-08 1:45 
AnswerRe: OleDb? Pin
Wendelius22-Dec-08 1:50
mentorWendelius22-Dec-08 1:50 
GeneralRe: OleDb? Pin
dec8222-Dec-08 1:57
dec8222-Dec-08 1:57 
GeneralRe: OleDb? Pin
Jay Royall22-Dec-08 2:37
Jay Royall22-Dec-08 2:37 
Questionget one row from each group Pin
R111922-Dec-08 1:09
R111922-Dec-08 1:09 
AnswerRe: get one row from each group Pin
Wendelius22-Dec-08 4:49
mentorWendelius22-Dec-08 4:49 
QuestionHow to refer dll from our Application Pin
SelvaSR21-Dec-08 22:49
SelvaSR21-Dec-08 22:49 
AnswerRe: How to refer dll from our Application Pin
Krishnraj21-Dec-08 22:59
Krishnraj21-Dec-08 22:59 
QuestionHow To Show "HINDI" words in JSP page and how to SAVE "HINDI" words in MySql...Plz Help Me.. Pin
kumar.cergenx21-Dec-08 19:59
kumar.cergenx21-Dec-08 19:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.