Solved

Avoid referring Column B to Column A and viz versa

Posted on 2007-11-14
6
311 Views
Last Modified: 2011-10-03
I want to avoid corss referring Column B to Column A and viz versa. I have a Column ( B ) refering to Column (A).  The following cases are fine
Col A Col B
1          2
2          3
3

but the following cases are not fine
Col A Col B
1          1
2          3
3          2

Can i do this in by using any database constraint?
0
Comment
Question by:x1877
  • 3
  • 2
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20279924
what about this:
Col A Col B
1          2
2          3
3          1

(ie the third row closing the "circuit" ?
0
 
LVL 14

Expert Comment

by:twoboats
ID: 20279992
To Angel's point - it's about travesing a network, to decide if it has rows. I did once write code (don't have it) that would deal with any number of levels in 2 passes. Couldn't do it in 1 pass (unless number of levels was known & fixed). Was a chunk of nightmarish code, so haven't kept it. Probably best achieved in a loop.
0
 
LVL 14

Expert Comment

by:twoboats
ID: 20279999
should read

decide if it has loops
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:x1877
ID: 20280056
angelIII:
Sorry according to busines logic even thats not possible. In that way my example is not perfect.
I am trying to achive the following

Col A Col B
1          2
2          
3          4
4
5           4
Means only 1 parent and 1 child or 1 parent and many children. No grandchild
0
 
LVL 14

Accepted Solution

by:
twoboats earned 500 total points
ID: 20280140
Don't think you can do it in a constraint, butr should be achievable in a trigger using self joins
0
 

Author Comment

by:x1877
ID: 20358627
trigger not tried...planning to do it using front end code.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now