tags:

views:

131

answers:

4

I am looking for hard to follow, large, pure readable and unsupportable SQL scripts with business logic. I need something overblown to illustrate Code vs SQL business logic. May be you have one?

Update: I am looking examples of terrible SQL. I am not looking for comparisons for these styles of business logic. May be you start task on inherited terrible SQL logic and you can share it. It could be absurd, funny or something like that. Actually, logic is not required queries are ok too.

+2  A: 

Anything with a trigger. They hide code off in unexpected places and create side effects that can be difficult to debug. Of course, triggers have their place, but you definitely need to use them with caution.

Joel Coehoorn
I've never liked triggers either...glad I am not the only one.
EJB
I do know pros and cons, but instead of writing my own example of terrible code, I am looking for exisiting.
Mike Chaliy
+1 GD triggers.... I have to disable them for every hotfix.
StingyJack
Once I inherited a project where the programmer used triggers to implement functionality that SQL Server provides for free with "ON DELETE CASCADE". *sigh*
Juliet
A: 

Having bad SQL to prove your point will not work as it doesn't prove anything other than people can write bad SQL. There can be bad code that does the exact opposite to what you want to prove.

You might want to look into describing the abilities of the development team in place. If coding is their strong point rather than SQL then that is the route that should be taken.

Robin Day
Sure, but I am looking for already existing code from bad guys...
Mike Chaliy
A: 

I've posted a few nasty bits of SQL I've encountered in the real world:

Embedding UI Logic in stored procedures

A sorry excuse for a database search (near the bottom of that post)

Maybe a simpler example would be using a cursor to perform functions which could be more easily accomplished using basic SQL. For example compare simple query using a WHERE or GROUP BY clause to a stored procedure which implements the same functionality using cursor.

Juliet
Thanks, but your SQL does not looks terrible...
Mike Chaliy
as far as i know, the only reason to use cursor is to mimic the FOR loop in sql, how do you do that with a "simple query using a WHERE or GROUP BY clause" ???
roman m
by using a conditional statement on a column in the current row
Bedwyr Humphreys
@Beds: how would i do the following: select 100 rows from a table, for each row - insert some of the columns into a different table, get SCOPE_IDENTITY(), and insert that along with some other columns from the initial select into a third table?
roman m
@rm: comments aren't a good place to discuss your question. Start a new question or consult the oracle: http://tinyurl.com/djftvy
Juliet
@Princess: i was just trying to figure out how to mimic a FOR-loop in sql w/o the cursor
roman m
+1  A: 

a fair comparison would show the same business logic in code vs sql

anything else is comparing apples to oranges - or worse, stacking the deck to support a foregone conclusion

Steven A. Lowe
do you have an example to illustrate that?
roman m
@rm: you must be joking
Steven A. Lowe