Q
Problem solve Get help with specific problems with your technologies, process and projects.

Creating a purchase form for a hospital database

Suppose I want to create a purchase form for a hospital database. How do I enter many product names under one bill number, which will be unique?

The underlying problem is that each bill can have zero or more detail lines. Each detail line has one product, so the decomposition into tables looks something like:

CREATE TABLE tBills (
   billId         INT       NOT NULL
   CONSTRAINT XPKtBills PRIMARY KEY (billId)
--  other bill attributes
   )

CREATE TABLE tProducts (
   productId  INT        NOT NULL
   CONSTRAINT XPKtProducts PRIMARY KEY (productId)
--  other product attributes
   )

CREATE TABLE tBillDetails (
   billDetailId INT       NOT NULL
   CONSTRAINT XPKtBillDetails
   PRIMARY KEY (billDetailsId)
,  billId         INT       NOT NULL
   CONSTRAINT XFK01tBillDetails
   FOREIGN KEY (billId)
   REFERENCES tBills (billId)
,  productId  INT        NOT NULL
   CONSTRAINT XFK02tBillDetails
   FOREIGN KEY (productId)
   REFERENCES tProduct (productId)
--  other detail attributes
   )
Although many people get confused on this issue, a bill can exist without detail lines. In fact when a bill is first created, it implicitly must exist without detail lines at least until the first detail line can be added. Think about the process when you write a bill manually if you doubt this!

For More Information


Dig Deeper on Oracle and SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close