- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Think of it like this, in OO terms:
The database is your "object".
Its tables are your object's "fields".
Stored Procedures are your objects "methods".
In general you want to keep your object's field hidden from outside view, and only access them through methods.
I write and maintain many database applications and I can tell you ones that don't use stored procedures are a nightmare to maintain from a database point of view. You have ad-hoc queries hitting the database instead of a fixed list of procedures, and keeping track of what indexes are needed and optimising the data access is made far for difficult.
Admin
CREATE PROCEDURE Something @intI AS INTEGER AS BEGIN SET @intI = @intI + 1 -- do someting actually useful here, can't be arsed for this example. Obviously just adding 1 to a variable doesn't require recursion, but some things seem to be more easily programmed recursively. IF @intI < 600 EXEC Something @intI END
Admin
I did not say I didn't go thru the change process, I just mean that the change process for DBA-level changes in all shops I've been in-not everywhere is less fraught with bureaucratic overhead
Admin
I'm a big fan of stored procedures, but I think SQL Server will try to cache the compiled SQL and query plan for ad-hoc queries if it can. So whilst performance was a big issue at one time, it is less of one now.
Even so, I'd still recommend stored procedures for security, ease of monitoring how the database is accessed, flexibility to change the underlying tables as long as the stored procedure is left unchanged, ability to use several steps to return result sets if this is more efficient, etc.
Admin
They had narrowed it down to two of us. Since everyone there had a beard, I had a beard, and the other applicant didn't, I got the job.
Admin
I found stored procedures are very useful to getting performance back where Linq to SQL just dies on its arse.
One example is searching a set of products based on name, code, manufacturer etc. These are all "OR" operations, building it in linq was painful and took a few seconds to execute. Writing it in a stored procedure reduced this to 60 odd milliseconds!
So optimise where necessary I guess.
Admin
[quote user="Dirge"][quote user="Jaime"] One of the errors I see people defending stored procedures make all of the time is to make easily falsifiable claims. Simply claiming that stored procedures are faster is not good enough. There are plenty of ways to tweak ad-hoc SQL to get within 0.01% of the performance of stored procedures, especially if the server isn't CPU-bound, which most aren't.[/quote]
Ad-hoc SQL is never going to have the execution plan(s) pre-built on the server side, is it? If not, there's a performance hit right there.
I can't speak for Oracle, but on SQL Server, stored procedures are great. They provide all sorts of opportunities to do processing on the DB server, instead of sending masses of data back and forth between the DB server and app server. The people who develop database software specialize in optimizing it for what it does, so why not let that software do that work for you instead of trying to code it yourself?
[quote] Since we are speaking MS-SQL Server, they have not pre-compiled for over 10 years, yes it has been over a decade since that statment that stored procedures are treated different then ad-hoc sql could be truthfully said about a recent software version. Some difference for CLR stored procedures.
As for optimizing database call go read up on high performance tuning and papers from places like amazon or google they all say the same thing ditch stored procedures. The truth is where stored procedures are used for CRUD in most cases they are alot slower then dyanamic parameterized SQL. The reason is they are full of ISNULL, COALEASE and CASE statments any they are slow, slow, slow. 10 years ago this was not the case and your statement is true.
The one main place where do see performance boost of dynamic parameterized SQL is in your example where you are having to process pass a bunch of data back and forth so that you can come up with a simple number. In that case yes stored procedures are probably the best thing to use, but then those cases are rare compared to all the simple CRUD that happens.
Admin
The friends roommate was sitting nearby and got really irate at the mention of the AI course.
It turned out that he was ticked off to find that they had a course in Artificial Insemination in Computer Science when they didn't have one in Agriculture that he could take for his degree.
Admin
I spent most of the day yesterday and I'm going to spend most of the day today doing phone interviews. If I circular-filed every resume because the candidate was awkward or made some kind of minor social snafu, I wouldn't have anyone left. With respect to appropriate behavior, there's a big gulf between "candidate mentioned during a casual interview that was going well that he/she once had a job in a mildly taboo industry" and "candidate was an argumentative asshole, or candidate whined during the interview that the questions were too hard [this just happened to me], or candidate smelled bad and picked his toes during interview."
If it comes down to you and one other person, and you mentioned something like that and the people you were interviewing with wanted to take it into account, might it cost you the interview? Sure. But there are lots of places to interview with out there.
Admin
Perhaps you could try reading up on, say, actual laws?
Discrimination is legal on any grounds except the ones that are illegal, such as : -
Age (unless they're too old / young / inexperienced / experienced)
Gender (unless they're the wrong gender)
Sexuality (unless they're just too unsexy or you're in one of those countries where sex is illegal & immoral; Saudi Arabia, Pakistan, America...)
Disability (unless they're, like, a freak?)
;)
Admin
You're new here, right?
Where I work, we use a farm of SQL servers. Gawd save us from the nonesense that hits the server without any thought of parameterisation, indexing, or plan optimisation... i.e. all the stuff from the sooper-dooper GUI that hangs IIS and SQL a dozen times a day.
Captcha "quibus" - to quibble about the silliest of things. Fancy THAT happening!
Admin
Admin
Well, some girls do and some girls don't.
Admin
That's a great point. think about how much better ZZ Top would have been if the drummer had a beard.
Admin
Please provide links to legislature (state or federal) that states felons, people from Spain and people over 40 are to be treated as protected groups.
kthxbye.
Admin
The real WTF is TDWTF accepts to publixh stories from the porn guy. Enough for me. I'm cuuting it with reading TDWTF
Admin
His name is Frank Beard, which I think would lose it's funniness if he actually had a beard.
Admin
Addendum (2011-01-28 10:46): that first sentence should read: The execution plan is prebuilt.
Admin
No. Atoms cannot be broken down into smaller components.
We just made a mistake when we named atoms "atoms".
Admin
Darn. That Large Hadron Collider is a complete waste of time & money; my electron microscope is running on empty, and the atom bombs are all bang and no rads.
Curse Quark and his pesky tricks (or was that Q in Star Trek?)
Admin
Whew, I'm glad I can still refuse to hire anyone who isn't a conservative Christian by claiming I don't like their necktie!
Loopholes are the only good thing about bad laws.
Admin
That's because we Portuguese run the US through secret societies.
Ever heard of the Knights of Columbus?
Admin
Admin
You will learn that there is no "if .. then .. else .." and there are no variables outside stored procedures.
(I do not claim that INFORMIX is anything other than TRWTF. But some companies are still running installations).
Besides that stored procedures allow to maintain fine-grained access control on the database server.
With ad-hoc SQL a user either has update permission on the whole table or on nothing. Stored procedures allow to grant access based on rules implemented in the stored procedure.
I know that your kind will re-implement access-control and maintenance of user permissions in the application server, because "Why use what we already have bought with the DBMS? You will be faster when you implement it yourself and finish the job in six weeks."
Admin
Thanks for clarifying that every person in the world is protected by the exact same "employment discrimination laws" (presumably created by Mr. Obama - Nobel peace prize winner and leader of the free world)regardless of which country they live in and what their legal status is..
Admin
But I'm glad we cleared it up.
You do realize that stored procedures typically have their own procedural language, don't you? There is a lot more you can do in a stored procedure than just run SQL statements. Before I do, I see that someone else has already taken up your challenge; let's see your response to them first.Admin
Loved the reference, thanks for the chuckle :)
Admin
The porn guy was a COMPLETE failure in that interview.
"Tell me something interesting you have worked on" in an IT interview should be intepreted as "I would like to know whether you will be interested in the type of work and challenges which we will be giving you."
Giving them a story about an unrelated job has absolutely no merit as a response to this question. He may as well have talked about unicorns.
Admin
WHILE @intI < 600 BEGIN SET @intI = @intI + 1 -- do someting actually useful here. Recursion is handy, but algorithms can often be written in a non-recursive manner. -- When recursion is actually desired, use a temporary procedure or implement this one bit of functionality as a stored procedure. END";
cmd.Parameters.AddWithValue("@intI", 6); cmd.ExecuteNonQuery();
I'm not against stored procedures, I simply think they aren't the only solution, and the alternatives are often better.
Admin
Admin
Isn't it usually illegal to ask for a photograph on a job application, what with anti-discrimination laws and all?
Admin
At first I didn't even catch the non-returnable photo good in that WTF. I was too distracted by the blatantly illegal request for the applicant's age. The photo seemed natural after the setup that they were eager to discriminate based on non-job related things.
Admin
Indeed. Some people fail to grasp what Turing Completeness actually means. Barring an external failure on the back-end or a badly made nested relationship, a pure SQL SELECT/INSERT/UPDATE/DELETE statement operates on a finite set of rows. It is a (somewhat poor) implementation of an algebra on finite sets of tuples. It is a language for writing deciders, programs that always halt solely on their finite input. SQL can never have the same expressive power in a stored procedure language like PL/SQL (based on Ada) or T-SQL. No way, no how.
Admin
Possibly true, but if in an interview you leave out all questions about things that the candidate might be able to learn, well, that wouldn't leave much to ask about, would it? I mean, any candidate could potentially learn any required skills given sufficient time and effort.
What do you expect a company to do in an interview if not ask the candidate about his exerience with tools and techniques that he will need to do the job? OF COURSE it would generally be foolish to reject a candidate for not having one particular skill, as long as he has most of what you need. But you have to ask about a variety of skills to find which ones he has and which ones he doesn't.
Admin
No. We would prefer if you sent some of Liz's photos.
Admin
That sure looks like:
Jaime: 0, Drak: 1
Admin
Well, in real life you would end up in court and you would have to convince the judge or jury that you didn't hire him because you didn't like his tie, while he would try to convince them that you didn't hire him because he is a Buddhist or whatever.
In real life, of course, it would be smarter to come up with a more plausible story, like you didn't hire him because he has no experience with Stored Procedures and you believe this to be a crucial job requirement.
Actually proving what the employer was thinking in one particular case is pretty hard. This is why so many discrimination lawsuits bring in statistical evidence, like, 30% of the people in our city are Portugease, but only 5% of this company's employees are Portugease, therefore they must be discriminating.
Of course many employers find this very frustrating because, no matter how much anti-discrimination activists may deny it, in real life there are many jobs that certain categories of people rarely apply for, so it's tough for an employer to meet these implied quotas. Like, relatively few cooks at Chinese restaurants are black people. Is this because Chinese restaurant owners discriminate against blacks? Or could it maybe be that not many blacks apply? Of course rap bands rarely hire Chinese people, so I guess the discrimination works both ways. Few Moslems are bartenders. Few auto mechanics are women. Few aerobics instructors are men. Etc etc. Most people accept that gender, culture, religion, and a host of other factors may influence a person's career choices. But anti-discrimination laws often refuse to recognize this and insist that if all bagpipe players are Scottish, this must be because you discriminated against everyone else. The statistics prove it.
Admin
That's a silly idea, but then that's what you'd expect from a Ron.
Admin
SqlCommand cmd = cn.CreateCommand();
cmd.CommandText = @"
CREATE PROC #payload(@i int OUTPUT) AS BEGIN SET @i = @i + 1 END";
cmd.ExecuteNonQuery();
cmd.CommandText = @"
WHILE @intI < 600 BEGIN EXEC #payload @intI OUTPUT END";
cmd.Parameters.AddWithValue("@intI", 6); cmd.ExecuteNonQuery();
cmd.CommandText = @"DROP PROC #payload"; cmd.ExecuteNonQuery();
Admin
Yes, that technique always works, but you can only apply it when both interviewers are bearded. It got me a job when I was desperate for work once. After my first pay packet I could then afford a razor, by which time it was too late for the company that hired me to decide they'd made a mistake, it would have been too much hassle to readvertise the job.
Admin
Admin
Admin
Admin
T-SQL actually is not SQL, it is an extension of SQL.
Admin
I use dynamic SQL when the query is stupid simple, or when it's too dynamic to write a stored procedure for (such as when I have query parts being populated by visitors to my business object). I use Stored Procedures when the query is complex and can benefit from the compile-time checking that occurs in SSMS when I create the procedure.
Admin
Oikeasti, joka ei ole tehnyt jotain tällaista?
Admin
I believe it's not illegal to require a picture of the interviewer when you're called in for an interview... stupid, maybe, but not illegal.
Admin
Next time, just make your claim clear and concise: Since the same code can be executed inside or outside a stored procedure, stored procedures are not inherently faster. Period. Not once did I disagree with you on that point.
Admin
I love how so many people on this site take an all-or-nothing approach. They either use stored procedures for any access to the database whatsoever or they ditch them completely.
Stored procedures are not for everything. If you're using them to reinvent standard RDBMS features, you're doing it wrong. Stored procedures are subroutines, plain and simple: encapsulated code, each performing a single, specific task. So if you have logic that appears in more than one place and it's not in a subroutine, you're doing it wrong too.
Admin
If he'd been out of the DB world for long enough that this is his first reaction to stored procedures, whether or not he misheard me, I don't want to be his gateway back into the DB world.