473,386 Members | 1,738 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,386 software developers and data experts.

Table Design Question

I am designing and product ordering database and have a design
question.
I have a Payments table which records all payments for a given
OrderID.
There are several payment methods (cash, credit card, check). Each of
these
payment methods has their own fields (i.e. CreditCardNum for payments
by credit card, CheckNum for payments by check, etc.)

If I place the CreditCardNum and CheckNum fields into a payments
table, it will not be correctly normalized (i.e. nulls will exist for
CheckNum when payment by credit card and vice-versa.)

So what should I do? Create separate payment tables for each type
payment method?
Does anyone know of a good database schema/framework which models a
typical ordering system (Orders, Payments, Invoicing, etc)?

Thanks
Jul 20 '05 #1
4 4430
Opa1 (op***********@yahoo.com) writes:
I am designing and product ordering database and have a design
question.
I have a Payments table which records all payments for a given
OrderID.
There are several payment methods (cash, credit card, check). Each of
these
payment methods has their own fields (i.e. CreditCardNum for payments
by credit card, CheckNum for payments by check, etc.)

If I place the CreditCardNum and CheckNum fields into a payments
table, it will not be correctly normalized (i.e. nulls will exist for
CheckNum when payment by credit card and vice-versa.)

So what should I do? Create separate payment tables for each type
payment method?


Real-world data does not always go well in hand with ideal data models.

In an object-oriented model, you would have a virtual base class
"payments", and then subclasses for each method that you could
instantiate.

Of course, you have have a main table, and the sub-tables for each payment
method, but this quickly goes out of hand. Then again, if you have 12 sub-
classes with over 100 attributes, and lump into all table, then things
also gets out of hand.

So in the end, you need to be pragmatic. For this case, it sounds like
one single table would be the best.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
For such problems, classic relational model provides type inheritance on
entity types whereby you have subtypes with inherited attributes from the
super type. Date's Introduction to Database systems, Chapter 13.9 (Entity
subtypes/super types: Pg. 433 on 7th Ed) has an excellent description of how
the model provides a clean solution using views to support logical
independence on base relations.

However, there is no *clean* way to do this in SQL even with sub table/super
tables. The recent SQL standard (SQL3) adds syntactic sugar with DDL for
super tables & sub tables. Note that these are semantic shortcuts and
provide no facility for type inheritance and hence SQL based DBMSs cannot
proactively provide support for such relationships.

For a practical solution, identify if payment methods are time-varying. If
they are, in other words, if, in the future, there could be other payment
methods other than cash, credit card & check, opt to represent them as
column in the payment table. Obviously you will have to deal with Nulls and
certain fact-based anomalies depending on the additional attributes like
CC#, check# etc.

If they are static, opt for the super type/subtype relationship, whereby you
can avoid Nulls and potential anomalies. However, beware that if there are
too many payment methods, a large number of tables to support super type/sub
type relationship can make the schema really clumsy.

--
- Anith
( Please reply to newsgroups only )
Jul 20 '05 #3
Thanks. I will take your advice.

Any info on a database framework/schema that I can modify for my
product ordering system?
Erland Sommarskog <so****@algonet.se> wrote in message news:<Xn*********************@127.0.0.1>...
Opa1 (op***********@yahoo.com) writes:
I am designing and product ordering database and have a design
question.
I have a Payments table which records all payments for a given
OrderID.
There are several payment methods (cash, credit card, check). Each of
these
payment methods has their own fields (i.e. CreditCardNum for payments
by credit card, CheckNum for payments by check, etc.)

If I place the CreditCardNum and CheckNum fields into a payments
table, it will not be correctly normalized (i.e. nulls will exist for
CheckNum when payment by credit card and vice-versa.)

So what should I do? Create separate payment tables for each type
payment method?


Real-world data does not always go well in hand with ideal data models.

In an object-oriented model, you would have a virtual base class
"payments", and then subclasses for each method that you could
instantiate.

Of course, you have have a main table, and the sub-tables for each payment
method, but this quickly goes out of hand. Then again, if you have 12 sub-
classes with over 100 attributes, and lump into all table, then things
also gets out of hand.

So in the end, you need to be pragmatic. For this case, it sounds like
one single table would be the best.

Jul 20 '05 #4
On 11 Dec 2003 11:34:45 -0800, op***********@yahoo.com (Opa1) wrote:

[snip]
There are several payment methods (cash, credit card, check). Each of
these
payment methods has their own fields (i.e. CreditCardNum for payments
by credit card, CheckNum for payments by check, etc.)

If I place the CreditCardNum and CheckNum fields into a payments
table, it will not be correctly normalized (i.e. nulls will exist for
CheckNum when payment by credit card and vice-versa.)

So what should I do? Create separate payment tables for each type
payment method?


It sounds like you're describing a supertype/subtype issue. Google
the database newsgroups for "supertype" and "subtype". In a (possibly
misleading) nutshell, attributes common to all subtypes (say, amount
tendered) go in the supertype's table; attributes unique to the
subtype (say, check number) go in the subtype's table. For 'n'
subtypes, you're looking at 'n' + 1 tables, 'n' views (each view joins
one subtype to its supertype), and a slew of CHECK constraints.
--
Mike Sherrill
Information Management Systems
Jul 20 '05 #5

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

Similar topics

7
by: mr_burns | last post by:
hi, is the table percent value for height used for displaying in browsers. i have a table i want to run to the bottom of the screen so it seemed best to set the height value to 100%. when i...
0
by: 2trax | last post by:
Hi all, I am trying to mimic the unix security model (users and groups) in a web app. I have thought of two ways of implementing this, but am unsure which would be better. The first design...
15
by: kimi | last post by:
I have just started working on a project that is partially complete. It is an application that is using access to store test results. The test results are being stored in two Access 2000 databases....
5
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
18
by: TORQUE | last post by:
Hi, Im wondering if anyone can help me with a problem. I have a form with more than 50 unbound fields. Some of the fields will be blank from time to time. This seems to be where im having...
7
by: david | last post by:
I have asked this question before. But it does not work for me. Given radion buttons in the web form design page. What I did is described as follows. A panel control is dragged into the design...
1
by: Mark | last post by:
Hi there gurus, can you please add your 2 cents on this design? We're having trouble relating these tables in a diagram because of the keys. Is it necesary to have the references setup? I would...
4
by: yanjie.ma | last post by:
Hi, I've got a two part question on table and form design (sorry for the length but it takes a bit to explain). Our sales department uses a look-up table to help the them select the best...
54
by: csolomon | last post by:
Hello: I was wondering if I could get some input on how to address a design issue, involving my composite table. I have one portion of my project complete. The following forms and reports I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.