How to solve the following problem ?

Hi,

Can anyone provide me help to to solve the following ? or just give me pointer that how to solve it please ?

Given n tables, R1, R2, …, Rn, such that the foreign key of table R2 references to the primary key of table R1 (RIC2), the foreign key of table R3 references to the primary key of table R2 (RIC3), …., the foreign key of table Rn references to the primary key of table Rn-1 (RICn), and the foreign key of table R1 references to the primary key of table Rn (RIC1).

1. Please describe how to create tables R1, …, Rn and to enforce all the referential integrity constraints RIC1, RIC2, …, RICn.
2. Please describe how to populate the data into tables R1, …, Rn.

Best Regards
LVL 13
Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ArtistCommented:
sonicefu, this looks very much like a homework problem, and unfortunately, EE Experts are not permitted to do homework problems for people.

If you have a specific question, you are welcome to ask it, and we can maybe help you with that.
Author Commented:
Let me explain it simple words that what I need.

I just want to know that how can I implement recursive relationships between tables as for as CREATE TABLE and UPDATE TABLE is concerned ?

This is my simple requirement, can you provide me simple hint to solve it ?
SQL Server DBA & Architect, EE Solution GuideCommented:
1. Just create the tables first which can be of any order..
2. Create the Primary keys of all tables if not done during table creation
3. Create Foreign keys in any order..

And Inserting data needs to be done in the following order:

1. Insert records into Table R1 with (foreign key of table R1 to table Rn) column as Null.
2. Insert into your tables starting with the Foreign key order RIC2, RIC3 and so on..
3. Update (foreign key of table R1 to table Rn) column with the actual value..

Note:

1. This is some kind of circular dependency indicating a bad design. ( Posting the tables and attributes can help me avoid this dependency)
2. (foreign key of table R1 to table Rn) column in Table R1 should be a nullable column..

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Thanks rrjegan17,

Can you elaborate a bit please
3. Update (foreign key of table R1 to table Rn) column with the actual value..

actually here Rn is referencing to R1 not opposite one

Is there specific SQL to use in the scenarios like this (MS-SQL)
SQL Server DBA & Architect, EE Solution GuideCommented:
>> actually here Rn is referencing to R1 not opposite one

Ok, Got it the other way..
In that case, you need to have R1 table inserted first before Rn

>> Is there specific SQL to use in the scenarios like this (MS-SQL)

Nothing specific, just follow the order in which the Foreign keys references..
Or in other words, Parent tables first and then the Child tables.
Author Commented:
thanks a lot rrjegan17 !
SQL Server DBA & Architect, EE Solution GuideCommented:
Welcome sonicefu
Kindly let me know if you have any other doubts..
Author Commented:
I'll come with examples.

Should I close this Question by giving you points and I'll ask a new question for more details ?
SQL Server DBA & Architect, EE Solution GuideCommented:
If you feel those examples are related to this question, then you can keep it open..
Else close this question and open up a new question as required..
Author Commented:
Thanks a lot !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.