Questions tagged [rbar]

RBAR is an acronym for Row By Agonizing Row, coined by Sr. DBA Jeff Moden, or in his words: "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row"

In the world of relational databases, RBAR means processing data on a row by row bases - which is also known as procedural approach, and it is one of the worst thing to do in terms of performance.

SQL works best with a set based approach, meaning processing data in batches rather then in single rows.

Numerous blog posts by multiple bloggers have discussed this issue - even before the RBAR acronym was coined.

12 questions
4
votes
1 answer

How to convert CURSOR based query in to SET based

I'm not a expert on SQL and I'm working on a huge SQL code and unfortunately it has a CURSOR which handles another two nested CURSORS within it (totally three cursors inside a stored procedure), which handles millions of data to be DELETE,UPDATE and…
Mar1009
  • 721
  • 1
  • 11
  • 27
3
votes
1 answer

pick enough items from several locations without doing rbar

I have a warehouse, where each itemnumber can be in several locations. I have a preferred order where to pick from. ITEM LOC IN_STOCK item_1 loc_1 3 item_1 loc_2 3 item_1 loc_3 2 item_2 loc_1 4 The preferred order is a function of the location…
Leif Neland
  • 1,416
  • 1
  • 17
  • 40
3
votes
2 answers

Cumulative Daily Sum for same day or before current record Date field in SQL

Important: I need this to be SQL Server 2000 compatible. I need a cumulative sum but based on current date field, an update query like the one I’m using now works but it’s terribly slow (ugly implicit RBAR triangular join): UPDATE #RPT SET…
Jcis
  • 153
  • 2
  • 15
3
votes
2 answers

Creating readable, unique key based on fields

The webguys wants unique urls based on the name of the products If more products have the same name, add a number after the name. our.dom/red-sock our.dom/red-sock-1 They do not want the product id or another number on all products,…
Leif Neland
  • 1,416
  • 1
  • 17
  • 40
2
votes
5 answers

Fast Export of Large Datatable to Excel Spreadsheet in VB.Net

I have an interesting conundrum here, how do I quickly (under 1 minute) export a large datatable (filled from SQL, 35,000 rows) into an Excel spreadsheet for users. I have code in place that can handle the export, and while nothing is "wrong" with…
Jeff Beese
  • 388
  • 2
  • 5
  • 19
1
vote
1 answer

MSSQL finding originator batch - without cursor

i'm looking for some help on the following on SQL2016 I have batches of which i need to identifying the parent batch. I'd need to fill is ParentBatchID and should work according to this logic: If there exists a previous batch where the current…
NiklaHUN
  • 11
  • 3
1
vote
1 answer

SQL Server - Set Based Waterfall

I have a table that stores numeric balances in different buckets (bucket 1, 2 and 3). When an amount is posted in the system, the amount must be allocated to the buckets. The transaction type determines how it affects the buckets. Type 1, 2 and 3…
p3pp
  • 45
  • 6
0
votes
0 answers

.NET Multi-Row SQL insert support for set based operation

If we want to insert multiple values into a table in SQL, we could use the following method: INSERT INTO MyTable VALUES (1,'a','foo'); INSERT INTO MyTable VALUES (2,'b','bar'); INSERT INTO MyTable VALUES (3,'c','foo'); INSERT INTO MyTable VALUES…
SE1986
  • 2,534
  • 1
  • 10
  • 29
0
votes
1 answer

SQL Server seems to behave in an async manner

I know SQL statements don't execute asynchronously by default, but I have a situation that appears to behave that way. Tables [#data] [tbl_Bucket] [tbl_IDPool] Procedures [sp_InsertIntoBucket] [sp_GenerateID] [sp_UpdateIDPool] Process An…
that0th3rGuy
  • 1,356
  • 1
  • 15
  • 19
0
votes
0 answers

SQL While Loop to find end of chain replacements/supersessions

I have read a bunch of information that processing a table RBAR is terribly inefficient, and while I know that was not what SQL was optimized for, I'm interested to see if there is a way that I can accomplish this task and avoid the loop or a set of…
rlphilli
  • 111
  • 1
  • 4
  • 17
0
votes
1 answer

SQL Server 2012 Insert a Set and Get all PK Values?

I have a sproc that takes a TVP, the input has 6,000 rows. The current code copies the TVP into a temp table, iterates RBAR over the temp table to insert a row on a real table, gets the Identity/PK value from the insert, updates the temp table with…
Snowy
  • 5,942
  • 19
  • 65
  • 119
0
votes
2 answers

SQL Server : call stored procedure with side effects for each row without using a cursor

Before you say this is identical to SQL Call Stored Procedure for each Row without using a cursor let me clarify my question: The stored procedure does have side effects. In fact, it's all about those side effects, as the results of each call…
MOHCTP
  • 1
  • 3