473,509 Members | 2,890 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Design Problem...Please Help!!

Hi,

I'm designing a simple database for filing system:

There are two levels of files (both look_up tables):
tlkpFile1, tlkpSubFile1 and a transaction table, tblFilings, for
filings (when documents ready for filings, user just pick the file name
from either look-up tables and insert to this table). tlkpSubFile1
includes files that are sub files from the files in tlkpFile1.
The design I have come-up with is like this:

tlkpFile1: tlkpSubFile1:
ID(PK) Name_File1 ID (PK) Name(FK_File1) Name_File2

1 Departmetns 1 Departments Marketing
2 Sales 2 Departments IT
3 Sales Jan
3 Sales Feb

My question is how should I design the tblFilings (transaction table)
with respect to those two look-up tables?? I'm thinking to have a
field, FiledIn, which will have a many-many relationship with both
fields in the look-up tables (Name_File1 and Name_File2)

tblFilings:
ID(PK) FiledIn

1 Sales **this from tlkpFile1
2 IT **this from tlkpSubFile1
MTIA,
Grawsha

Jul 23 '05 #1
7 1239
If there are only two levels of parent and sub file then it looks like
you could do it with something like the following. This is based mainly
on my own assumptions. You are in a much better position than I to
understand your requirements.

CREATE TABLE Files (file_id INTEGER PRIMARY KEY, file_name VARCHAR(20)
NOT NULL UNIQUE, parent_file_id INTEGER NULL REFERENCES Files
(file_id))

CREATE TABLE Filing (file_id INTEGER REFERENCES Files (file_id))

Forget the concept of "lookup tables". Good database designers don't
recognize such a thing. All entities are treated as equal in the
relational model and there is only one type of table. Also, practically
everyone hates "tbl" prefixes on tables. They only make the name harder
to read and everyone will think you are an Access programmer ;-).

--
David Portas
SQL Server MVP
--

Jul 23 '05 #2
Thanks david,

This is what I want. Now, If want to add one more sub_sub level table
(its one-many relationship to tlkpSubFile1), do I need to modify the
design? I did test the table (the new one )and found it ok, unless I'm
missing something. Please help.
MTIA,
Grawsha

Jul 23 '05 #3
You should be OK with the design of the Files table to represent the
hierarchy as long as the maximum number of hierarchy levels is know.
For a hierarchy of unknown maximum depth it doesn't work so well
because there isn't a set-based way to relate all levels of the tree in
a single query.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #4
>> For a hierarchy of unknown maximum depth it doesn't work so well
because there isn't a set-based way to relate all levels of the tree in
a single query. <<

That is what a nested set model does. The levels are determined by
(rgt-lft), with a larger difference meaning a higher level and 1 being
a leaf node.

Jul 23 '05 #5
"--CELKO--" <jc*******@earthlink.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
For a hierarchy of unknown maximum depth it doesn't work so well

because there isn't a set-based way to relate all levels of the tree in
a single query. <<

That is what a nested set model does. The levels are determined by
(rgt-lft), with a larger difference meaning a higher level and 1 being
a leaf node.


True, or soon through recursion via a recursive WITH, a set-based,
declarative, Standard-compliant (since SQL:1999), and portable
(already provided by DB2 and Oracle) form which we'll finally (!)
see in SQL Server 2005. This is not to say that I wouldn't prefer
a nested-set-model approach still in many cases, I would, but the
possibilities with a recursive WITH are interesting for those wanting
to both keep it relationally pure and computationally more complete.
And, yes, I do mean in addition to tree algorithms.

--
JAG
Jul 23 '05 #6
>> This is not to say that I wouldn't prefer a nested-set-model
approach still in many cases, I would, but the
possibilities with a recursive WITH are interesting for those wanting
to both keep it relationally pure and computationally more complete.
And, yes, I do mean in addition to tree algorithms. <<

I don't like CTE for trees because it is a loop that runs under the
covers and gets expensive when you do a WITH RECURSION. But to use it
for creating a VIEW on the fly to avoid repeating a derived table over
and over is really handy:

WITH (<<horrible complex query>> ) AS X (..)
SELECT X1.a, X2.a, ...
FROM X AS X1, X AS X2
WHERE X1.foo_date = X2.foo_date - INTERVAL '1' DAY;

Jul 23 '05 #7
"--CELKO--" <jc*******@earthlink.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
This is not to say that I wouldn't prefer a nested-set-model

approach still in many cases, I would, but the
possibilities with a recursive WITH are interesting for those wanting
to both keep it relationally pure and computationally more complete.
And, yes, I do mean in addition to tree algorithms. <<

I don't like CTE for trees because it is a loop that runs under the
covers and gets expensive when you do a WITH RECURSION. But to use it
for creating a VIEW on the fly to avoid repeating a derived table over
and over is really handy:

WITH (<<horrible complex query>> ) AS X (..)
SELECT X1.a, X2.a, ...
FROM X AS X1, X AS X2
WHERE X1.foo_date = X2.foo_date - INTERVAL '1' DAY;


With respect to tree queries, sure, there might be practical efficiency
considerations for substituting recursion for a node numbering scheme
like the nested set model. And, for what it does, it's simple and clever.
However, as more is demanded of a query language, pushing it towards
computational completeness, a cornerstone of this is the ability to loop,
as required by Turing completeness. Think now not about tree queries
but about such things as graph algorithms like shortest path or combinatorial
algorithms like all subsets of integers whose sum equals some value (with
no a priori upper bound on the cardinality of such sets). So given the
ultimate necessity to loop, one can loop imperatively (control statements in
T-SQL or SQL PSM) or loop declaratively using recursion (recursive WITH),
the latter being more compatible with the high-level declarative nature of the
relational model and SQL.

--
JAG
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1680
by: Kurt Watson | last post by:
I’m having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web...
6
2063
by: Tiraman | last post by:
Hi , I have a stored procedure which return an xml by using the (for xml auto/explicit) which working fine under the Query Analyzer . and i would like to build simple function that get the sp...
1
2590
by: SpookyET | last post by:
I want to create a wrapper for SQLite and I'm having a problem with getting NullReferenceException when calling the unmanaged function. I do not wish to write in C++ since i do not have enough...
0
1654
by: Walter | last post by:
Hi, can someone please help me with my custom control viewstate problem....I haven't slept for hours trying to get this fixed. I am making two custom controls which will be included on a single...
0
1460
by: nt91rx78 | last post by:
Our college changes 18 weeks semester to 16 semester, so our CS professor cannot finish teaching the last important chapter which is related with my problw\em. This is program C problem Anyone...
4
1653
cyberking
by: cyberking | last post by:
Hi, I have a website http://www.projectvtu.com Now this website has frames in all of its pages. The problem I am facing now is that the website works very well on my subnet at home. But, I...
9
2484
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
2
3515
by: violeta123 | last post by:
I am stuck! Please help It might be difficult to explain the problem via email, but I will try. I have a Win 2003 Enterprise server running with the only purpose of a membership web site...
0
1359
by: sa6113 | last post by:
I want to connect to a Windows machine in my network , using ssh, I use paramiko but I have problem in authentication, would you please help me? 1- I have installed freeSSHD in server machine? Is...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.