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 3303652
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:58:46+00:00 2026-05-17T20:58:46+00:00

i have a self referencing table called project that has a master detail relationship

  • 0

i have a self referencing table called project that has a master detail relationship between parent projects, and sub-projects, sub-sub-projects…

one of the fields is releaseId and i need to make sure that the parent projects release id is the same for all its subs…

table fields are projectId, parentProjectId, releaseId

anyone have a clue on how to run such a report in sql 2005?

  • 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-17T20:58:46+00:00Added an answer on May 17, 2026 at 8:58 pm

    Ok this is untested and makes some assumptions. First assumption is that the id numbers are integers and that the releaseid will never be 0. Next assumption is the projectid is the PK of the table. Final assumption is that you can tell the parentproject because the parentid is null.

    Now the only correct way to do this is in trigger. That way it will always be correct no matter how the data is changed. There is no other completely reliable way to ensure the data stays in synch. Triggers must be written to handle multiple records. This trigger is a rough approximation and is not tested. Be sure to thoroughly test a trigger (including tesiting a multiple rcord insert and a multiple record update) before using it.

    create trigger testtrigger on mytable
    for insert, update
    as
    
    select inserted.projectid as parentid, inserted.releaseid as newreleaseid
    into #changedparentreleaseid
    from inserted i 
    join deleted d 
      on i.projectid = d.projectid
    where i.parentid is null
    and isnull(d.releaseid,0) <> isnull(i.releaseid,0)
    
    update m
    set releaseid = c.newreleaseid
    from mytable m
    join #changedparentreleaseid c
      on c.parentid = m.parentid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that has an Self referencing relationship - One Wall comment
I have a table called Metrics that is a self-referencing table. Meaning it has
I have a database table called item that has a self-referencing field called itemParentID.
I have a self referencing table named categories that has a parentcategoryid column that
I have a self-referencing many-to-many relationship between users and managers that looks like this:
I have a self referencing table in Oracle 9i, and a view that gets
I have a self-referencing table (Customers) and a table that will link to one
I have a self referencing table and I want a mysql query that will
I have a table in my source DB that is self referencing |BusinessID|...|ParentID| This
I have a self-referencing table with content like this: Self-referencing parent table ID ParentID

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.