views:

196

answers:

5

This isn't a joke. ;)

I was working with a DBA to define a data model and he was pushing back against some of my suggestions by saying something like "well before we had 'loop based' programming" or "loop based data models"

My suggestions, because we are working with Entity Framework, a model == table schema based ORM, were to simplify some relationships.

I want to know what he meant by that?


Thanks for the answers so far but its definitely not a sql "set-based" vs cursor,while loop thing.


In response I said "I have no idea what that means" and he never provided an answer, just dropped some part of his objections.

+2  A: 

I would infer that he means loop-based as distinct from set-based programming, which is a better way to code with SQL.

For example, in a loop-based mental model, you would change a bunch of rows by running a query, fetching the rows one-by-one, changing the value of a field, and post each row back to the database. This runs N+1 SQL queries to change N rows. It's often the consequence of using ORM tools like Entity Framework or Active Record.

In a set-based mental model, you'd use a single SQL UPDATE statement to change all the rows in one operation. You don't have to fetch any data back to the application, it all happens on the database server. And you only have to run a single SQL statement. This is more efficient, but most ORM tools fail to support this technique (except by allowing you to bypass the ORM and execute custom SQL directly).


Re comments from other folks: We can come up with answers for what we think "loop-based" means, but this will never answer what your coworker meant when he said it. If he backed off, then he might not know how to be more articulate about it. If so, you'll never know what he meant.


Re ORMs are smarter than that these days, I'd like to hear some examples. I'm not denying it -- I'm genuinely interested in an example of an ORM that can invoke an update against rows it hasn't fetched. That is, within the "ORMish" interface, not by breaking the abstraction.

Bill Karwin
ORMs are smarter than that nowadays...
Kalmi
Not all of them.
Randolpho
I've only seen custom home brew DAL layers do that sort of thing.
jfar
A: 

Maybe he was referring to avoid loops in a stored proc.

Having loops in Transact-SQL are usually bad practices, SQL is made to retrieve data in a fast way without loops.

Maybe he was also referring for an entity having multiple children. And when an instance of that entity is created, its children are retrieved in a loop instead of with a single query, we often see that in ORM. But ORMs have hints we can tell them to avoid that.

Hope this helps

Mike Gleason jr Couturier
A: 

My guess is that he was referring to the way it was done in classic ASP where there was a RecordSet object and you would loop through the results of a query to render the page. I can't see what this would have to do with creating a good schema though.

Drew
+1  A: 

From your question, it appears that he is saying that you should avoid Set-based operations because they were the old way..."before we had loop-based programming."

This is like dangling red meat before a lion - if that is what he is really saying.

So - challenge him. "What do you mean? - Do you mean the use of cursors?" "Are you suggesting that 'loop based' (really, cursor-based) manipulation of data in the database is better than Set-based operations? - or Vice Versa?" If he actually means that you should learn the Set-based approach native to SQL, then you may well have something to learn from the guy. If he is savvy about the kinds of compromises inherent in many ORMs (even if they are smart enough to not just devolve everything to operations looping over records retrieved), then you definitely have something to learn from him.

If, on the other hand, he thinks that cursors are a snazzy new invention that helps you escape the hassle of that SQL set-based stuff, then you have a real problem if this guy is your DBA!

Oh, and one other thing, there's lots of stuff I don't know but I have many years of deep SQL development experience. Indeed, I've written some SQL that'll make your hair curl. And I gotta tell you - I never heard the term "loop-based programming." So do not take it as something of a standard term or art or something you should have known.

Good luck...

Mark Brittingham
A: 

"I'm genuinely interested in an example of an ORM that can invoke an update against rows it hasn't fetched."

I do have doubts whether such a possibility would actually be a good idea.

Modifying database values without the modifier KNOWING the actual content that he is modifying ?

That's like saying to someone, "Whatever it is you think you know (and I don't even really know what it is that you think you know), it's wrong."

Erwin Smout