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

  • SEARCH
  • Home
  • 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 119421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:39:02+00:00 2026-05-11T03:39:02+00:00

Rules like A parent object will have up to 2 children could be enforced

  • 0

Rules like ‘A parent object will have up to 2 children’ could be enforced in database using triggers. But would it be a good idea to duplicate the rule if this rule is already enforced in the domain layer.

In which cases duplication of such rules are justified? Are there any alternative to avoid such duplication? Is it not a data integrity rule?

Thanks

  • 1 1 Answer
  • 3 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. 2026-05-11T03:39:02+00:00Added an answer on May 11, 2026 at 3:39 am

    It’s virtually impossible to do this correctly in code that’s outside the database. Any code that looks to see if 2 records already exist and if not then allows a new record to be added can be fooled by 2 threads operating simultaneously on the same parent. Unless you actually lock the database table or somehow serialize the child addition process, either of which create a real lack of scalability.

    You don’t mention the RDBMS so it’s hard to give you a solution.

    EDIT:

    I agree with those who say that triggers are far from clean. But they are not the only way to enforce rules within a database. That is why I said without knowing your RDBMS, it would be impossible to suggest any database solution or even one that may not require a trigger.

    Beside, you shouldn’t need a trigger because your middle tier never does DML, it just calls database procedures or packages which encapsulate your CRUD. RIght?!

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

Sidebar

Related Questions

Is it possible to format price according to rules like this using DecimalFormat in
So I rewrote my paths to something like: URL/really/nice/paths/ using mod_rewrite rules like this:
I would like to kwnow if it possible for users to add validation rules
I have a chicken-egg problem. I would like too implement a system in PHP
I have some Oracle tables that represent a parent-child relationship. They look something like
Say I have a Boost Spirit grammar like this, where a parent rule passes
I'm attempting a centered, two-column layout and I'd like to have horizontal rules in
I have 3 tables in my SQL Server database: Teacher Student Parent Each of
I have a composite primary key table (Maintenance Items). I would like to create
Like the question says. After a solver.solve(); I want to see specific rules (with

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.