Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 581523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:35:16+00:00 2026-05-13T14:35:16+00:00

I need some suggestions to implement a business rule – whether to keep it

  • 0

I need some suggestions to implement a business rule – whether to keep it in DB (using TRIGGERs) or in App code.

--- Table structure:---

# ORG - Master table for Organizations 
# USER - Master table for Users (each user belongs to an Org so there's a field OrgId which is FK ro ORG) 
# SITE - Master table for Sites

# ORGSITE - {OrgId, SiteId} links Site(s) with Org(s) 
# USERSITE - {UserId, SiteId} links Site(s) with User(s)

The constraint is that : “A site is accessible to a User ONLY if its accessible to his Organization.”


Now, it happens in the app that on day1 we relate Site1 to Org1 and then we’re able to relate Site1 to User1 (User1 belongs to Org1). On day2 I delete the relationship between Site1 & Org1 from ORGSITE (this requires that I also delete the corresponding User1 & Site1 relationship from the USERSITE table).

This is handled from within the app code. So, now my question is where shud I keep the above constraint handling –

APPROACH#1:

Deploy TRIGGERs on the ORGSITE table and USER table which will handle the activity for:

  1. On after delete for ORGSITE (delete
    corresponding USERSITE records)

  2. Onafter update for USER (if User’s
    Org is changed then delete all his
    records from USERSITE)

APPROACH#2:

Handle everything from within the code – tap the events which trigger those DB actions and delete records from USERSITE (as and when necessary). Need to manage via a Transaction.

APPROACH#3:

Simply, add a new field OrgSiteId in the USERSITE table which is an FK ref to an ‘Auto Increment PK: Id’ of ORGSITE. Next, I’ll deploy the cascaded delete for the USERSITE.OrgSiteId FK. This will handle most of the things and make it implicit!

Hope I explaind well. Is APPROACH#3 really gonna work? If not – what is your preference and why?

Thank you for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:35:17+00:00Added an answer on May 13, 2026 at 2:35 pm

    If you think someone would ever run a query straight from the DB (someone like, say, a DBA) then you should handle it in a trigger. If you do it through the app, you have to always do it through the app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some asp.net pagination code samples. I would like suggestions on open source
I need some suggestions for how to implement a very basic mechanism that logs
Need some regular expressions help. So far I have my code working to allow
Need some guidance figuring out what went wrong. I've been using mysql, phpmyadmin for
I need to implement some workflow functionality; for example, user submits a document, it
I am trying to implement paging in PHP, using Json. I need the data
I need some advice how to implement this situation in my application. I have
I write code in isolation, that is I work for myself. I need some
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some quick advice I am trying to access a object array but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.