File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes DB constraints at application or DB level? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "DB constraints at application or DB level?" Watch "DB constraints at application or DB level?" New topic
Author

DB constraints at application or DB level?

Denise Hum
Greenhorn

Joined: Oct 09, 2001
Posts: 20
I'm working on a small application using servlets & a database, and I was having a debate with someone this morning... In general, is the "norm" to have application level integrity checking only or at both the application level and database level. That is, is it overkill to set up primary and foreign key constraints, not null, etc at the database level as well?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

That is, is it overkill to set up primary and foreign key constraints, not null, etc at the database level as well?


Forgive me if I'm missing your boat, but it seems that you are asking whether you should implement database constraints in the database.

Well, yeah. Otherwise, where's the "database" in the database constraints?

If you are asking whether the application should pre-check for these constraints before attemptng a database operation, that's a much longer conversation.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Denise Hum
Greenhorn

Joined: Oct 09, 2001
Posts: 20
Ok, let me clarify where I'm coming from. I am just returning to programming from a few years hiatus. When I worked on projects before, I did both application and database level checking. So I was surprised when I spoke with someone this morning and he said that I was "so stuck in 1999" because no one uses primary/foreign key/not null/etc constraints in the database anymore because it should be handled by the application these days. I just wanted to see if this is truly the case and if this is some new methodology that people use these days.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

no one uses primary/foreign key/not null/etc constraints in the database anymore




Ummm, well, I guess I can't speak for everybody, but at evey place I've worked anyone who made such an assertion would be on the short list of people whose participation in the Salary Continuation Program was suspect.

But maybe I'm just a 1999 throwback too. :roll:
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I've been saved from my own stupidity more than once by having foreign key constraints.

Why anyone would consider not using them when they're available is beyond me.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Denise Hum
Greenhorn

Joined: Oct 09, 2001
Posts: 20

I've been saved from my own stupidity more than once by having foreign key constraints.
Why anyone would consider not using them when they're available is beyond me.


These were my thoughts exactly. Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

Ditto.

Here's why. If you only have it in the application.

1 More maintenance in the application, but it is a good trade-off, because why add network traffic if the data is known that it wouldn't be good.

OK, then why the database, because not every call to the database is guaranteed to be from your application. Especially with the web, there are some great hackers that can get to your database and put in bad data. Or maybe even another applicaiton at your company that doesn't know those rulse and puts in bad data.

Tell the person that said "1999" that they need a new line, I am sure they use that line over and over again.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DB constraints at application or DB level?