473,769 Members | 5,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cascade updating/deleting and 3 tier architecture

Hi everyone,

Wonder if anyone can shed some light on how i should setup cascade
deletes of object data within my database.

One option is to use SQL triggers, is this a good idea? Should the
logic be in my business layer instead? or maybe even the data access
layer?

I also have the problem when performing an insert. If i insert a
record into one table, i also need to insert other values into foreign
key tables. Again, where do i do this?

This is my first 3 tier application and i am not sure which way i
should set this up, so any help would be greatful.

Thanks in advance

Sep 25 '06 #1
1 1457

I don't think there's really a right answer to this - but I will try to give
my $.02 on the subject. When you split up the work in an n-tier architecture,
there are many different things to do based upon your environment and your
application. You can start out by being rigid on certain techniques, but you
are going to find that you will have to bend the rules a bit in different
scenarios.

#1 - make use of your database engine where appropriate. There are definite
performance gains to be had when you use the database engine to do certain
activities. In other words there are times when you don't want to bring over
data to your middle tier to process it because of speed. A lot of times
writing stored procedures are the way to go when you have to do database
activities with a lot of volume.

#2 - make sure you know where your code is. If you are working in an
environment with multiple developers, a lot of times it's nice to have ALL of
the logic in the middle tier, because everyone knows where to look for the
code. If you start writing code in triggers and stored procedures, make sure
the team (and yourself) knows that this is occurring. There's nothing worse
than debugging a routine and 'magic' seems to be happening to your data. And
of course it's happening due to a stored procedure or trigger that everyone
has forgotten was in the database.

#3 - a lot of times you can't do it in the database. For example let's say
you have some complex logic that needs to occur on every row of a cascading
delete. Sometimes doing this in the database can be a nightmare and lead to
bad recursion potential, etc. Or during this process you need to return some
key values to some other functions etc. You may be forced not to put your
cascades in the database, and you may have to drop back to the middle tier to
perform the complex logic. (however this might not be true anymore in SQL
2005 - i have yet to explore this)

A good way to approach this might be to put all of your cascading deletes in
the database to start off with. Then, as situations arise, move the ones that
can't be done in your database out to the middle tier...

....I'm not sure there is a right answer here for every situation. You want
to try to make some standards for your project, and try to adhere to them in
most situations as best you can. Real world development however likes to
intrude on even the most sincere plans and you may end up violating your
standards once or twice (or your norms) simply to get the user what they
really need.

--
Franklin M. Gauer III
Applications Development Manager
Integrated Companies, Inc.
"Nemisis" wrote:
Hi everyone,

Wonder if anyone can shed some light on how i should setup cascade
deletes of object data within my database.

One option is to use SQL triggers, is this a good idea? Should the
logic be in my business layer instead? or maybe even the data access
layer?

I also have the problem when performing an insert. If i insert a
record into one table, i also need to insert other values into foreign
key tables. Again, where do i do this?

This is my first 3 tier application and i am not sure which way i
should set this up, so any help would be greatful.

Thanks in advance

Sep 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
5694
by: nospam | last post by:
Reasons for a 3-tier achitecture for the WEB? (NOTE: I said, WEB, NOT WINDOWS. DON'T shoot your mouth off if you don't understand the difference.) I hear only one reason and that's to switch a database from SQL Server to Oracle or DB2 or vice versa... and that's it.... And a lot of these enterprises don't need it as they already know what database they are going to use and they don't plan on switching in and out database in the first...
0
5913
by: Fraser Hanson | last post by:
Hello, I have a table which has a foreign key relationship with itself. I want and expect my updates to cascade (deletes definitely cascade as expected) but instead I just get error 1217: foriegn key error. I have written example code to use in reproducing the problem: # Create the table
25
5627
by: David Noble | last post by:
We've been developing a web site using 3-tier architecture for 18 months now. There is a common layer that defines the classes - using XML schemas. The data layer acts as a wrapper to 3 databases - SQL Server, Oracle and AS400. The business layer exposes web services which communicate with the front end, ASP.Net. All 3 tiers are on different boxes. This works well. Now I am leading a team to build a winforms app. I need some advice as
33
4313
by: Lee C. | last post by:
I'm finding this to be extremely difficult to set up. I understand that Access won't manage the primary key and the cascade updates for a table. Fine. I tried changing the PK type to number and setting default value to a UDF that manages the auto-numbering. Access won't take a UDF as a default value. Okay, I'll use SQL WITHOUT any aggregate functions, for the default value. Access won't do that either. Okay, I create a second...
4
7023
by: Patrick | last post by:
I'm writing a winforms database application in C#. I've come across a lot of stuff lately about "N-Tier" architecture. Can anyone give me a simple explanation of N-Tier? The descriptions that I've found online are chock full of lingo that I simply don't know. I need the "N-Tier" for Dummies description. Talk to me like I'm in kindergarten. Of course, I'm particularly interested in how N-Tier relates to creating a winforms database...
3
14520
by: RAJESH | last post by:
I am working with c# and asp.net in developing web applications, iam using ..netframework 1.1 ,i want to know what is the need of 3-tier or 4-tier architecture in our application development.what is its part when some body is using our application.plese give links where i can find the answer.
1
1400
by: Nemisis | last post by:
Hi everyone, Wonder if anyone can shed some light on how i should setup cascade deletes of object data within my database. One option is to use SQL triggers, is this a good idea? Should the logic be in my business layer instead? or maybe even the data access layer? I also have the problem when performing an insert. If i insert a
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.