# Relational Database question (MS Access)

**URL:** https://boards.straightdope.com/t/relational-database-question-ms-access/151319
**Category:** Factual Questions
**Created:** [January 27, 2003, 8:18pm UTC](https://boards.straightdope.com/t/relational-database-question-ms-access/151319 "2003-01-27T20:18:38Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![BioHazard](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@BioHazard](https://boards.straightdope.com/u/BioHazard)
#### Post date: [January 27, 2003, 8:18pm UTC](https://boards.straightdope.com/t/relational-database-question-ms-access/151319/1 "2003-01-27T20:18:38Z")

</div>

I am trying to make a relational database that can support as many catagories and subcatagories and sub sub cats, etc as possible. What I mean is something that can emulate a directory structure (Ie as many folders in folders as possible) using very few tables as possible.

What I did is create a table in Access with 3 fields. CatID, CatName, and SuperCat. SuperCat is related back to CatID, but is not required. It SEEMS like it works, but I haven’t tried any SQL queries yet, but I’m sure the query will be very complicated.

Is there a better, more robust and “safer” way to make this DB? How would you do make this? If anyone knows and likes SQL, please feel free to make the query for my table or any people post.

Thanks

---

<div class="post-metadata">

### Author: ![BioHazard](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@BioHazard](https://boards.straightdope.com/u/BioHazard)
#### Post date: [January 27, 2003, 8:23pm UTC](https://boards.straightdope.com/t/relational-database-question-ms-access/151319/2 "2003-01-27T20:23:17Z")

</div>

And let me add that I have the flu really bad and can’t think straight right now.

---

<div class="post-metadata">

### Author: ![zev\_steinhardt](https://avatars.discourse-cdn.com/v4/letter/z/97f17d/32.png) [@zev\_steinhardt](https://boards.straightdope.com/u/zev_steinhardt)
#### Post date: [January 27, 2003, 8:39pm UTC](https://boards.straightdope.com/t/relational-database-question-ms-access/151319/3 "2003-01-27T20:39:24Z")

</div>

You’ve got the idea. What you need is a recursive table, as you laid out. The only thing that I can add to this is to place a restriction on the SuperCat column that the values placed in it must be present in the CatID column.

Zev Steinhardt

---

<div class="post-metadata">

### Author: ![jsc1953](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jsc1953](https://boards.straightdope.com/u/jsc1953)
#### Post date: [January 27, 2003, 8:40pm UTC](https://boards.straightdope.com/t/relational-database-question-ms-access/151319/4 "2003-01-27T20:40:04Z")

</div>

So what you have is a recursive relationship between cat and supercat, which you’ve physically represented in a single table.

I think Access supports that–if you write a select query for all Cats where SuperCat = x, it’ll write a nested SQL statement. but it should work.

---

<div class="post-metadata">

### Author: ![BioHazard](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@BioHazard](https://boards.straightdope.com/u/BioHazard)
#### Post date: [January 27, 2003, 8:56pm UTC](https://boards.straightdope.com/t/relational-database-question-ms-access/151319/5 "2003-01-27T20:56:36Z")

</div>

**Zev** - The problem with placing the restriction on the SuperCat colum is that the highest level Cats would need to point somewhere. How do I get over this?

---

<div class="post-metadata">

### Author: ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)
#### Post date: [January 27, 2003, 9:39pm UTC](https://boards.straightdope.com/t/relational-database-question-ms-access/151319/6 "2003-01-27T21:39:37Z")

</div>

> [@](#):
>
> \*Originally posted by BioHazard \*  
> \*\ ***Zev** - The problem with placing the restriction on the SuperCat colum is that the highest level Cats would need to point somewhere. How do I get over this? \*\*

Two tables, one for top-level categories, and the other for everything else.

Or put in a special element which is its own supercategory, and have all the top-level categories claim it as their parent.

---

<div class="post-metadata">

### Author: ![zev\_steinhardt](https://avatars.discourse-cdn.com/v4/letter/z/97f17d/32.png) [@zev\_steinhardt](https://boards.straightdope.com/u/zev_steinhardt)
#### Post date: [January 27, 2003, 9:43pm UTC](https://boards.straightdope.com/t/relational-database-question-ms-access/151319/7 "2003-01-27T21:43:50Z")

</div>

> [@](#):
>
> \*Originally posted by BioHazard \*  
> \*\ ***Zev** - The problem with placing the restriction on the SuperCat colum is that the highest level Cats would need to point somewhere. How do I get over this? \*\*

You could have it be null, or self-referencing.

Zev Steinhardt

---

<div class="post-metadata">

### Author: ![BioHazard](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@BioHazard](https://boards.straightdope.com/u/BioHazard)
#### Post date: [January 27, 2003, 10:22pm UTC](https://boards.straightdope.com/t/relational-database-question-ms-access/151319/8 "2003-01-27T22:22:21Z")

</div>

Ill Have it be null, seems like that will be easier.

The BIG question is: Will this import into SQL server??? Ill find out eventually…

---

<div class="post-metadata">

### Author: ![zev\_steinhardt](https://avatars.discourse-cdn.com/v4/letter/z/97f17d/32.png) [@zev\_steinhardt](https://boards.straightdope.com/u/zev_steinhardt)
#### Post date: [January 27, 2003, 10:27pm UTC](https://boards.straightdope.com/t/relational-database-question-ms-access/151319/9 "2003-01-27T22:27:11Z")

</div>

> [@](#):
>
> \*Originally posted by BioHazard \*  
> \*\*Ill Have it be null, seems like that will be easier.
> 
> The BIG question is: Will this import into SQL server??? Ill find out eventually… \*\*

Yes, it will. And with SQL Server, you can put a constraint on the table to make sure that the values come from the other column.

Zev Steinhardt
