2

I have the following tables:

Part-Product Line relationship

Each ProductLine will encompass many Parts. For this reason, it initially seemed to me that the Part table is a child of the ProductLine table. However, a part is not simply an extension of a product line, and when I asked myself if it is possible to a part to exist without a product line, the answer seems to be yes.

So I'm wondering if the above design appears to be correct or if there is a better design. In the Part table, PartBase can be thought of as the unique identifier for each part (the part number if you will.)

As a somewhat unrelated question, I have these tables set up as a one to many relationship. Since each Part must belong to a ProductLine but cannot belong to more than one, is it more correct to have this as a one-and-only-one to many relationship? Is the only difference that a Part must contain a not null ProductLineNumber in the actual database? Is that different from requiring that ProductLineNumber be not null?

To follow up to @HandyD's comment, as a business rule, every part must belong to exactly one product line. However, when I was thinking about a part as a physical object, it shouldn't need a product line to exist (a product line is just a label after all.) I'm comparing here to how a sale needs a customer to make sense, so that a Sale table would more clearly be the child of a Customer table. Is this distinction between Part-ProductLine and Sale-Customer a false one?

3
  • 1
    You're contradicting yourself a bit - "when I asked myself if it is possible to a part to exist without a product line, the answer seems to be yes." but later you stated "Since each Part must belong to a ProductLine but cannot belong to more than one". The key question you need to answer - does a Part require an associated ProductLine or not? If yes, then does a Part only link to one ProductLine?
    – HandyD
    Commented May 31, 2019 at 0:14
  • 1
    @HandyD Maybe I'm confusing myself when trying to think about this in terms of a parent-child relationship. Yes, as a business rule, every part must belong to exactly one product line. However, when I was thinking about a part as a physical object, it shouldn't need a product line to exist (a product line is just a label after all.) I'm comparing here to how a sale needs a customer to make sense, so that a Sale table would more clearly be the child of a Customer table. Is this distinction between Part-ProductLine and Sale-Customer a false one? Commented May 31, 2019 at 15:22
  • 1
    In addition to parent-child relationships, there are also generalization-specialization relationships. The word "extension" implies that you are thinking somewhat in these terms. If you think of product lines as having parts, you are thinking one way. If you think of parts as extending product lines, you are thinking the other way. If you try to think both ways at once, you will be confused. Commented Jul 16, 2020 at 10:17

2 Answers 2

1

If the business requirement is

a business rule, every part must belong to exactly one product line.

So if the rule is, each part belongs to one product line the other side of that relationship is each product line contains zero-to-many parts which should convince you this is a clear instance of a parent/child relationship.

How a something exists in the real world versus how it exists within a business context/database are not always strongly tied. If I have a part on my desk I do not care about it's product line. But if I'm a business and I am selling the part I will probably need to categorize that part for search/reporting/sales/commission purposes.

The other columns you will probably need FKs on (PartType, Grade, Family, PopularityCode, UnitClass) will have the same physical implementation (parent table, foreign key reference) even if the context might not be the same (Each Part is described by One Part Type/PartType describes zero-to-many Parts, etc).

Won't get into the column types or other aspects of the design because that's not pertinent to the question but I'll be happy to provide guidance elsewhere.

0

Like in Part Table,

PartID int PK
PartBase varchar(20) AK
PopularityCode char(20) 

Similarly In ProductLine Table ,PK column should be of INT datatype.

Even if ProductLine table is small,it may be FK in Huge Table . So if ProductLineNumber varchar(20) is Index then it may affect performance.

So it should be ,

ProductLine Table

ProductLineID int PK
ProductLineNumber varchar(20) AK

ProductLineID should be reference in other columns.

Now come the main question.

Foreign Key can be null-able also.

So if as per your Biz. requirement, Part cannot exists without Product Line then,

create table Part (
    Partid int   ,
    PartBase varchar(20) not null,
    ProductLineID int   not null,
    primary key(PartID,ProductLineID)

);

So PartID,ProductLineID will be composite primary key.

if Part can exists of its own Product Line then ProductLineID will be Nullable FK.

then Main question is ,

How many nullable ProductLineID  rows will be there in Part table ?



create table Part (
    Partid int  primary key ,
    PartBase varchar(20) not null,
    ProductLineID int  null,
    PopularityCode char(20)     
);

I assume Nullable ProductLineID rows will be very negligible 1% or 2%.

In that case Create Unique Filtered index,

CREATE UNIQUE  INDEX 
    FUX_Part_ProductLine
ON dbo.Part 
    (Partid,ProductLineID ) 
WHERE 
    ProductLineID IS NOT NULL ;

When did you mention anything about PopularityCode ?

Even if PopularityCode is not mention in question,even if there is no issue of Partial Dependency,still we need Mapping Table.

So New Design of Part table,

 create table Part (
        Partid int  primary key ,
        PartBase varchar(20) not null,
        PopularityCode char(20)     
    );

Create Mapping table

 create table ProductLine_Part_Mapping (
        Partid int  not null ,
        ProductLineID int  not null,
        primary key(PartID,ProductLineID)
    );

It is better to create Mapping table in One-to-Many or Many-to-Many relation.

It help specially when records are in millions.

So Partid is Independent or not,this design is OK.

If you mention thing like ,

One Productline may contain how many PartID ? How many rows will be there in each table ?

These question in help in making Index.

2
  • By setting the primary key in the Part table as (PartID,ProductLineID) aren't you possibly introducing partial key dependency? For instance PopularityCode is entirely dependent on PartBase and has nothing to do with ProductLine. Commented Jun 6, 2019 at 20:35
  • PopularityCode was always in the question. And also ProductLine-Part is a many to one relationship (or many to one-and-only-one relationship as I mentioned being unsure of.) But still I don't think this answers my original question about the parent-child relationship of these tables. Commented Jun 7, 2019 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.