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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:45:51+00:00 2026-05-22T19:45:51+00:00

Say I have a table named EMPLOYEE, and the table has a field called

  • 0

Say I have a table named EMPLOYEE, and the table has a field called ManagerID. This field is a FK to another record of the EMPLOYEE table of who their manager is. What is an ideal way to verify that there is no circular reference (recursive foreign keys)?

EDIT – Let me add that every employee does NOT need a manager. There will be some employee records that do not have their ManagerID field set.

*Example: User 123 has User 345 as their manager. User 345 has User 567 as their manager. For some crazy reason, User 567 has User 123 as their manager.

I want to check if User 345 is in a circular reference.*

What is the best way to figure this out? A simple query? Business logic code (C#/VB.NET)?

What have other people done?

Example table schema –

-- Employee Table --
UserID (int - PK)
ManagerID (int - FK to another UserID; can be null)
  • 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-22T19:45:52+00:00Added an answer on May 22, 2026 at 7:45 pm

    Here’s a few starters – they either use recursive CTEs or cursors:

    http://blogs.msdn.com/b/sqlazure/archive/2010/07/01/10033575.aspx

    http://social.msdn.microsoft.com/Forums/en-ZA/transactsql/thread/50a0bd26-87c8-4197-84f9-5fb1dfd792b6

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

Sidebar

Related Questions

Say I have a table called Employee (has ID , NAME , ADDRESS ,
I have many tables, say T1, T2, T3. Every table has a column named
Say you have a table named Product and it has an auto-number/identity column. Do
I have two tables, both named as say, Employee in two different schema HR
Lets say I have table named Place with columns: placeId int not null auto_increment,
Say I have a table named items : id int(11) ... tag int(11) And
Let's say I have a table like this: name |order_id ======================= first_record | 0
Say I have a table called Users, which contains your typical information: Id, Name,
Say I have a Companies table which has a many-many relationship with an Employees
Hopefully that title makes sense... Let's say I have an employee table: ID |

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.