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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:17:55+00:00 2026-05-28T07:17:55+00:00

I see that most people just hate having a circular dependency in the database

  • 0

I see that most people just hate having a circular dependency in the database design. And since the support for this is “tricky” in most database engines, I was wondering if there’s a way around this design:

I have a users table and a pictures table

Every picture has an userId (the user who inserted it)
Every user has a profile picture

I might just create a ProfilePictures table, but it would cause issues in some other places (like picture comments).

I’m aware that there are some other questions related to this issue, but they’re more related to partent-child relationships, which is not the case here.

So, is it ok to use a circular dependency here? or if not, how would you avoid it?

  • 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-28T07:17:55+00:00Added an answer on May 28, 2026 at 7:17 am

    Without circular references between tables:

    User 
    ------
    userid NOT NULL
    PRIMARY KEY (userid)
    
    Picture
    ---------
    pictureid NOT NULL
    userid NOT NULL
    PRIMARY KEY (pictureid)
    UNIQUE KEY (userid, pictureid)
    FOREIGN KEY (userid)
      REFERENCES User(userid)
    
    ProfilePicture
    ---------
    userid NOT NULL
    pictureid NOT NULL
    PRIMARY KEY (userid)
    FOREIGN KEY (userid, pictureid)        --- if a user is allowed to use only a
      REFERENCES Picture(userid, picture)  --- picture of his own in his profile
    
    FOREIGN KEY (pictureid)                --- if a user is allowed to use any 
      REFERENCES Picture(picture)          --- picture in his profile
    

    The only difference with this design and your needs is that a user may not have a profile picture associated with him.


    With circular references between tables:

    User 
    ------
    userid NOT NULL
    profilepictureid NULL                  --- Note the NULL here
    PRIMARY KEY (userid)
    FOREIGN KEY (userid, profilepictureid)   --- if a user is allowed to use only a
      REFERENCES Picture(userid, pictureid)  --- picture of his own in his profile
    
    FOREIGN KEY (profilepictureid)           --- if a user is allowed to use any 
      REFERENCES Picture(pictureid)          --- picture in his profile
    
    Picture
    ---------
    pictureid NOT NULL
    userid NOT NULL
    PRIMARY KEY (pictureid)
    UNIQUE KEY (userid, pictureid)
    FOREIGN KEY (userid)
      REFERENCES User(userid)
    

    The profilepictureid can be set to NOT NULL but then you have to deal with the chicken-and-egg problem when you want to insert into the two tables. This can be solved – in some DBMS, like PostgreSQL and Oracle – using deferred constraints.

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

Sidebar

Related Questions

This may seem obvious to most people, but I'm just trying to confirm that
I've tried searching for this, but most people just want to convert hex values
I know most of the time people just do a LIKE '%$search_query%' but see
I see that EF can update a model based on an existing database schema.
I see that over on this question LINQy way to check if any objects
I see that there is PostSharp AOP support for Silverlight, but is there a
I was wondering if anyone knew why some programming languages that I see most
I've just arrived to Node.js and see that there are many libs to use
I see that within MySQL there are Cast() and Convert() functions to create integers
I see that in PL/SQL it is possible to set the session state of

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.