473,382 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to normalize these relationships?

I have three tables with a relationship I've never worked with
before. Can anyone suggest/comment on the best way to create a third
normal form relationship between these tables?

The tables basically are:

TRAIN (TRAIN_ID and 15 columns about train specs, etc)
TRUCK (TRUCK_ID and 12 columns about truck specs, etc)
TRANSPORTATION_ITEM
This table has, among others, two columns, TRUCK_ID and TRAIN_ID. If
the truck column is used there can be no data in the train column and
vice versa.

This relationship seems denormalized to me, but I don't remember how
to normalize it. Does anyone know the correct name for this kind of
relationship?

thanks!

Mar 4 '07 #1
8 2985
Assuming you aren't repeating data in TRANSPORTATION_ITEM then you are
already satisfying one of the normalisation principles.i.e minimising
redundancy.
Even though what you are doing in TRANSPORTATION_ITEM will work, I would
separate into 2 tables with distinctive names for the tables.
--

Jack Vamvas
___________________________________
The latest IT jobs - www.ITjobfeed.com
<a href="http://www.itjobfeed.com">UK IT Jobs</a>
<bb*****@gmail.comwrote in message
news:11*********************@s48g2000cws.googlegro ups.com...
>I have three tables with a relationship I've never worked with
before. Can anyone suggest/comment on the best way to create a third
normal form relationship between these tables?

The tables basically are:

TRAIN (TRAIN_ID and 15 columns about train specs, etc)
TRUCK (TRUCK_ID and 12 columns about truck specs, etc)
TRANSPORTATION_ITEM
This table has, among others, two columns, TRUCK_ID and TRAIN_ID. If
the truck column is used there can be no data in the train column and
vice versa.

This relationship seems denormalized to me, but I don't remember how
to normalize it. Does anyone know the correct name for this kind of
relationship?

thanks!

Mar 4 '07 #2
(bb*****@gmail.com) writes:
I have three tables with a relationship I've never worked with
before. Can anyone suggest/comment on the best way to create a third
normal form relationship between these tables?

The tables basically are:

TRAIN (TRAIN_ID and 15 columns about train specs, etc)
TRUCK (TRUCK_ID and 12 columns about truck specs, etc)
TRANSPORTATION_ITEM
This table has, among others, two columns, TRUCK_ID and TRAIN_ID. If
the truck column is used there can be no data in the train column and
vice versa.

This relationship seems denormalized to me, but I don't remember how
to normalize it. Does anyone know the correct name for this kind of
relationship?
It's difficult to say exactly from this scant information. Judging from
the anme, TRANSPORTATION_ITEM is a supercalls, of which TRAIN and TRUCH
are heirs, to speak in object-orirent terms. In such case, it feels
backwards to me that TRUCK_ID and TRAIN_ID appears in TRANSPORTATION_ITEM.
I'd rather have a TRANSPORTATION_ITEM_ID that also would be the key in
thr TRAIN and TRUCK tables.

But the purpose of TRANSPORTATION_ITEM may be different, in which case
TRAIN_ID and TRUCK_ID as mutually exclusive columns makes perfect sense.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Mar 4 '07 #3
The classic scenario calls for a root class with all the common
attributes and then specialized sub-classes under it. As an example,
let's take the class of Vehicles and find an industry standard
identifier (VIN), and add two mutually exclusive sub-classes, Sport
utility vehicles and sedans ('SUV', 'SED').

CREATE TABLE Vehicles
(vin CHAR(17) NOT NULL PRIMARY KEY,
vehicle_type CHAR(3) NOT NULL
CHECK(vehicle_type IN ('SUV', 'SED')),
UNIQUE (vin, vehicle_type),
..);

Notice the overlapping candidate keys. I then use a compound candidate
key (vin, vehicle_type) and a constraint in each sub-class table to
assure that the vehicle_type is locked and agrees with the Vehicles
table. Add some DRI actions and you are done:

CREATE TABLE SUV
(vin CHAR(17) NOT NULL PRIMARY KEY,
vehicle_type CHAR(3) DEFAULT 'SUV' NOT NULL
CHECK(vehicle_type = 'SUV'),
UNIQUE (vin, vehicle_type),
FOREIGN KEY (vin, vehicle_type)
REFERENCES Vehicles(vin, vehicle_type)
ON UPDATE CASCADE
ON DELETE CASCADE,
..);

CREATE TABLE Sedans
(vin CHAR(17) NOT NULL PRIMARY KEY,
vehicle_type CHAR(3) DEFAULT 'SED' NOT NULL
CHECK(vehicle_type = 'SED'),
UNIQUE (vin, vehicle_type),
FOREIGN KEY (vin, vehicle_type)
REFERENCES Vehicles(vin, vehicle_type)
ON UPDATE CASCADE
ON DELETE CASCADE,
..);

I can continue to build a hierarchy like this. For example, if I had
a Sedans table that broke down into two-door and four-door sedans, I
could a schema like this:

CREATE TABLE Sedans
(vin CHAR(17) NOT NULL PRIMARY KEY,
vehicle_type CHAR(3) DEFAULT 'SED' NOT NULL
CHECK(vehicle_type IN ('2DR', '4DR', 'SED')),
UNIQUE (vin, vehicle_type),
FOREIGN KEY (vin, vehicle_type)
REFERENCES Vehicles(vin, vehicle_type)
ON UPDATE CASCADE
ON DELETE CASCADE,
..);

CREATE TABLE TwoDoor
(vin CHAR(17) NOT NULL PRIMARY KEY,
vehicle_type CHAR(3) DEFAULT '2DR' NOT NULL
CHECK(vehicle_type = '2DR'),
UNIQUE (vin, vehicle_type),
FOREIGN KEY (vin, vehicle_type)
REFERENCES Sedans(vin, vehicle_type)
ON UPDATE CASCADE
ON DELETE CASCADE,
..);

CREATE TABLE FourDoor
(vin CHAR(17) NOT NULL PRIMARY KEY,
vehicle_type CHAR(3) DEFAULT '4DR' NOT NULL
CHECK(vehicle_type = '4DR'),
UNIQUE (vin, vehicle_type),
FOREIGN KEY (vin, vehicle_type)
REFERENCES Sedans (vin, vehicle_type)
ON UPDATE CASCADE
ON DELETE CASCADE,
..);

The idea is to build a chain of identifiers and types in a UNIQUE()
constraint that go up the tree when you use a REFERENCES constraint.
Obviously, you can do variants of this trick to get different class
structures.

If an entity doesn't have to be exclusively one subtype, you play with
the root of the class hierarchy:

CREATE TABLE Vehicles
(vin CHAR(17) NOT NULL,
vehicle_type CHAR(3) NOT NULL
CHECK(vehicle_type IN ('SUV', 'SED')),
PRIMARY KEY (vin, vehicle_type),
..);

Now start hiding all this stuff in VIEWs immediately and add an
INSTEAD OF trigger to those VIEWs.

Mar 5 '07 #4
I think there are a couple of ways you can go here. First is an
assessment of what the business logic behind the TRANSPORTATION_ITEM
table is. If it simply for output for the interface then move the
business logic up into code. If that is not possible, or there is
truly data that needs to be saved for another purpose, the the other
route would be to add the TRANSPORTATION_ITEM id to the truck and
train table. That should give you the normalization you require and
reduce the NULL fields in the TRANSPORTATION_ITEM table which is what
it appears you are really after. Then your query can join the from
the train or truck table to the TRANSPORTATION_ITEM table.
Mar 5 '07 #5
On Mar 4, 11:00 am, bbcr...@gmail.com wrote:
I have three tables with a relationship I've never worked with
before. Can anyone suggest/comment on the best way to create a third
normal form relationship between these tables?

The tables basically are:

TRAIN (TRAIN_ID and 15 columns about train specs, etc)
TRUCK (TRUCK_ID and 12 columns about truck specs, etc)
TRANSPORTATION_ITEM
This table has, among others, two columns, TRUCK_ID and TRAIN_ID. If
the truck column is used there can be no data in the train column and
vice versa.

This relationship seems denormalized to me, but I don't remember how
to normalize it. Does anyone know the correct name for this kind of
relationship?

thanks!
You can have two extra columns. For transportation_item table one
column will be source with values 'truck' or 'train'. The other column
is id with values for truck_id or train_id.

Mar 6 '07 #6
On Mar 5, 11:02 am, "myke.dil...@gmail.com" <myke.dil...@gmail.com>
wrote:
I think there are a couple of ways you can go here. First is an
assessment of what the business logic behind the TRANSPORTATION_ITEM
table is. If it simply for output for the interface then move the
business logic up into code. If that is not possible, or there is
truly data that needs to be saved for another purpose, the the other
route would be to add the TRANSPORTATION_ITEM id to the truck and
train table. That should give you the normalization you require and
reduce the NULL fields in the TRANSPORTATION_ITEM table which is what
it appears you are really after. Then your query can join the from
the train or truck table to the TRANSPORTATION_ITEM table.
Yeah, I was really unclear when I wrote that initial post- I had to
get it out and move onto something more pressing. There is a one to
many relationship where truck and train "types" are used in multiple
transportation_item records. So that would increase the amount of
truck records if I included transportation_item in that table.

thanks!

Mar 6 '07 #7
This is the time when I mention that I purchased Joe Celko's "SQL For
Smarties" several years ago and felt it was a great companion for
learning standard SQL theory. I recommend the book for everyone who
wants to take it to the next level.

I suspect that this entire database I inherited from a group project
of multiple contractors will have to be overhauled to achieve true
third normal form, but cannot be for financial and scope reasons.

I certainly was able to identify 3 mutual columns between the trucks
and trains and can suggest building a join table with that data and a
vehicle_ID that's used as the join with the transportation_item.

thanks!

Mar 6 '07 #8
>>This is the time when I mention that I purchased Joe Celko's "SQL For Smarties" several years ago and felt it was a great companion for learning standard SQL theory. I recommend the book for everyone who wants to take it to the next level. <<

Why, so do I!! An amzaming cooncidence :) !!

Mar 7 '07 #9

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

Similar topics

3
by: Christos TZOTZIOY Georgiou | last post by:
I found at least one case where decombining and recombining a unicode character does not result in the same character (see at end). I have no extensive knowledge about Unicode, yet I believe that...
0
by: Megan | last post by:
Hi Everybody- I know that this is a really, really long post, but I wanted to try to give you as much background as possible. So here's a quick overview of the issues I'm asking for help with:...
2
by: Max | last post by:
Hi. I really hope someone can help me. Going slowly insane with this problem. I have a two Access 2000 databases. One is the backend containing tables and some admin queries. The other is the...
7
by: davegb | last post by:
I'm totally new to relational database design. My boss has asked me to create a database of information on the employees in our group. Seemed to me like a simple application to learn the ropes. A...
45
by: salad | last post by:
I'm curious about your opinion on setting relationships. When I designed my first app in Access I'd go to Tools/Relationships and set the relationships. Over time I'd go into the window and see...
3
by: Janelle.Dunlap | last post by:
I have a table in my database that is linked to an excel spreadsheet. I need to be able to manipulate the data in this linked table so that I can create smaller normalized tables that work with...
4
by: kollatjorva | last post by:
Hi all I'm trying to get a value from an xml node 'Publisher' use the value as a name of an .css class. This works fine until I get a value from the Publisher node with white space in it. I've...
5
by: =?iso-8859-1?B?TWF0dGlhcyBCcuRuZHN0cvZt?= | last post by:
Hello! I'm trying to find what package I should use if I want to: 1. Create 3d vectors. 2. Normalize those vectors. 3. Create a 3x3 rotation matrix from a unit 3-d vector and an angle in...
13
by: ARC | last post by:
Hello all, Prior to going live with my app, I have questions on relationships theory. My prior app was done in Access 97, and I did NOT use relationships at all. I have 65 tables in my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.