|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, January 18, 2013 2:22 PM
Points: 162,
Visits: 262
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, October 12, 2009 3:16 AM
Points: 14,
Visits: 5
|
|
This is an excellent article the gave an idea have to solve some problems that arise from the need of paraller processing. Thank you very very much. As all we want is right resource planning I show in the following article that its better to create temporary tables and use INSERT INTO instead of SELECT INTO. As the article says its a resources matter. The article is here:http://www.sqlservercentral.com/articles/Basic+Querying/temptablesinsqlserver/1279/ Thank you.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, October 12, 2009 3:16 AM
Points: 14,
Visits: 5
|
|
As I am new to SQL i cannot understand why you are using the statement SELECT * INTO #LockHelp FROM Rainfall_Events WITH (TABLOCKX) WHERE 1=2. This statement does not fetch any rows? I't must be somenthing about the lock time, bit can you explain me why you are using "WHERE 1=2"? Thank you
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, July 29, 2011 4:14 AM
Points: 318,
Visits: 198
|
|
iermis (10/12/2009) As I am new to SQL i cannot understand why you are using the statement SELECT * INTO #LockHelp FROM Rainfall_Events WITH (TABLOCKX) WHERE 1=2. This statement does not fetch any rows? It must be something about the lock time, bit can you explain me why you are using "WHERE 1=2"? Thank you
I think Sunny is using this "WHERE 1 = 2" for creating the #LockHelp table only, having no data. But not sure why, because he has not refer #LockHelp in the SP.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, July 29, 2011 4:14 AM
Points: 318,
Visits: 198
|
|
| Nice article. Keep it up.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, January 18, 2013 2:22 PM
Points: 162,
Visits: 262
|
|
Hi iermis
Thanks for the comments. The query you mentioned is only for getting a Table Lock on the table. We dont actually need any records from the table but at the same time we want to have the table locked from the Rest_OrphanLocks SP until the records are marked as processed. The condition "1=2" does exactly that. It does not spend time retrieving records but locks the table. #LockHelp Temporary table is optional. We could as well have a SELECT query instead of SELECT INTO
Thanks Satish More
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, January 18, 2013 2:22 PM
Points: 162,
Visits: 262
|
|
mohd.nizamuddin (10/12/2009)
I think Sunny is using this "WHERE 1 = 2" for creating the #LockHelp table only, having no data. But not sure why, because he has not refer #LockHelp in the SP.
Thanks Nizamuddin. #LockHelp is optional. You can as well have only a SELECT query instead of SELECT INTO. The only difference is that it returns an empty result set back to the SP caller
Thanks Satish More
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, March 27, 2013 5:24 AM
Points: 8,
Visits: 25
|
|
Thank you all for your fast replies.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 7:30 AM
Points: 1,566,
Visits: 600
|
|
I recently (within the last 2 years) created a system to monitor our SQL instances from a central instance. Without going into details about the whole process, I had a requirement to run multiple tasks to retrieve data from the monitored instances in parallel (one or more instances unavailable would cause delays in retrieving data from all the other instances). There's an easier way to do this than messing with lock hints, use the UPDATE ... OUTPUT format of the UPDATE query. Here's a snippet of the code that I use:
-- ****************************************************************************************** -- Create the local temp tables used in this proc CREATE TABLE #DRT_Update ( DataRetrievalTaskID INT) -- ******************************************************************************************
-- ****************************************************************************************** -- Clear the temp table ... ProcessNextServer: DELETE #DRT_Update -- ******************************************************************************************
-- ****************************************************************************************** -- Get the next Data Retrieval Task to be processed - set the status to 2 for the record selected. UPDATE DataRetrievalTask SET [Status] = 2 OUTPUT inserted.DataRetrievalTaskID INTO #DRT_Update WHERE DataRetrievalTaskID = (SELECT MIN(DataRetrievalTaskID) FROM DataRetrievalTask WHERE [Status] = 1 AND StartTime <= GETDATE() ) -- ****************************************************************************************** This process is easily scalable - I just have to create another job to execute the Stored Proc to add another process. This way, you dont have to worry about Locks etc - the SQL Engine does it for you.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, March 27, 2013 5:24 AM
Points: 8,
Visits: 25
|
|
| Can you explain the code?
|
|
|
|