# Developers and DBAs: book on best practices

**URL:** <https://boards.straightdope.com/t/developers-and-dbas-book-on-best-practices/621301>\
**Category:** In My Humble Opinion\
**Created:** [May 8, 2012, 5:54pm UTC](https://boards.straightdope.com/t/developers-and-dbas-book-on-best-practices/621301 "2012-05-08T17:54:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khadaji](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@Khadaji](https://boards.straightdope.com/u/Khadaji)\
**Post date:** [May 8, 2012, 5:54pm UTC](https://boards.straightdope.com/t/developers-and-dbas-book-on-best-practices/621301/1 "2012-05-08T17:54:57Z")

</div>

For most of my career I have developed software that talked to and/or ran machines. Now I find myself doing more and more database work.

While I understand the basics, I want to learn best practices. As one “for instance”: when is it better to use a view or stored procedure?

I know \*how \*to use a view or stored procedure, but I want to learn more about _when_ to use them.

Please recommend some good books.

---

<div class="post-metadata">

**Author:** ![MobiusStripes](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@MobiusStripes](https://boards.straightdope.com/u/MobiusStripes)\
**Post date:** [May 8, 2012, 6:04pm UTC](https://boards.straightdope.com/t/developers-and-dbas-book-on-best-practices/621301/2 "2012-05-08T18:04:02Z")

</div>

I applaud your desires. (Probably because they mirror mine.) I’ve been highly disappointed not to find satisfactory answers to most of my “which is best” questions. It turns out that most of the things I ask seem to have “it depends” answers, or competing “best” solutions depending on who you ask.

On the topic of stored procedures, my personal preference (at present; I reserve the right to change my mind) is to write my own queries in DAOs and avoid store procedures. Much of this is due to the environment I work in where the database engine is liable to be changed on me, or I have to switch back and forth between a few. Stored procedures don’t shift well, but raw SQL queries work fine so I tend to stay with the lowest common denominator. That likely comes with some performance cost.

I also have been resistant to the useof ORMs. I dislike “magic boxes” and prefer to fully know/understand what is going on. That said I’ve been using Hibernate on a recent project and I have enjoyed (most) of it.

---

<div class="post-metadata">

**Author:** ![TriPolar](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tripolar/32/3008_2.png) [@TriPolar](https://boards.straightdope.com/u/TriPolar)\
**Post date:** [May 8, 2012, 6:05pm UTC](https://boards.straightdope.com/t/developers-and-dbas-book-on-best-practices/621301/3 "2012-05-08T18:05:15Z")

</div>

A lot of that will depend on the particular application and database system. Sorry, I don’t have a book to recommend.

A view is a set of data created at run-time based on a query. The query is usually pre-compiled and optimized. A stored procedure is a function with capabilities that vary widely across database systems. When analogous to a view, a stored procedure would be used to perform processing that wouldn’t be available or difficult to accomplish using a standard query. It would also be used where the result wouldn’t be a table of information.

There should be on-line resources where these topics are discussed in detail. The database provider will usually provide information specific to optimal performance for their product.

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [May 8, 2012, 6:53pm UTC](https://boards.straightdope.com/t/developers-and-dbas-book-on-best-practices/621301/4 "2012-05-08T18:53:53Z")

</div>

> [@MobiusStripes](#):
>
> It turns out that most of the things I ask seem to have “it depends” answers, or competing “best” solutions depending on who you ask.

In a lot of cases, these really are the right answers.
