Re: Best practice kinda question
From: --CELKO-- (remove.jcelko212_at_earthlink.net)
Date: 12/05/04
- Next message: John A Grandy: "Re: trigger sql syntax errors (very difficult to troubleshoot)"
- Previous message: Bonj: "SQL Server logs event on connection"
- In reply to: Michael C: "Best practice kinda question"
- Next in thread: Michael C: "Re: Best practice kinda question"
- Reply: Michael C: "Re: Best practice kinda question"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 04 Dec 2004 17:09:38 -0800
>> But should I add CompanyID to every table that will be related to
Company? <<
Yes, of course. How else would you know that it is, in fact, related to
the company? Dr. Codd's rules? All relationships are shown by values
in columns of tables.
Your skeleton schema had some serious errors.
Was the computed totals column in invoices redundant or do you really
price by the invoice in a manner unrelated to the items purchased? Did
you really want all of the MONEY datatype problems?
Are you one of those newbies who thinks that IDENTITY "id" columns are a
replacement for a key? Sorry, it is a way to destroy data integrity and
mimic a magnetic tape file system.
You showed a vague magical "id" in Invoices, but it never appears in
Invoice items. I'll bet you changed data element names from table to
table, which will destroy the data dictionary. Please read any data
modeling book or the ISO-11179 Standards.
Here is a new skeleton:
CREATE TABLE Customers
(cust_id INTEGER NOT NULL PRIMARY KEY,
name VARCHAR(35) NOT NULL,
..);
CREATE TABLE Invoices
(company_id INTEGER NOT NULL
REFERENCES Companies(company_id),
invoice_nbr INTEGER NOT NULL,
PRIMARY KEY (company_id, invoice_nbr),
cust_id INTEGER NOT NULL
REFERENCES Customers(cust_id),
..);
CREATE TABLE InvoiceItems
(company_id INTEGER NOT NULL,
invoice_nbr INTEGER NOT NULL,
FOREIGN KEY (company_id, invoice_nbr)
REFERENCES Invoices(company_id, invoice_nbr),
product_id INTEGER NOT NULL, -- refs Inventory
amount DECIMAL(12,4) NOT NULL,-- not priced from Inventory?
PRIMARY KEY (invoice_nbr, product_id));
CREATE TABLE Companies
(company_id INTEGER NOT NULL PRIMARY KEY, -- DUN number?
company_name VARCHAR(35) NOT NULL);
--CELKO--
Please post DDL in a human-readable format and not a machne-generated
one. This way people do not have to guess what the keys, constraints,
Declarative Referential Integrity, datatypes, etc. in your schema are.
Sample data is also a good idea, along with clear specifications.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
- Next message: John A Grandy: "Re: trigger sql syntax errors (very difficult to troubleshoot)"
- Previous message: Bonj: "SQL Server logs event on connection"
- In reply to: Michael C: "Best practice kinda question"
- Next in thread: Michael C: "Re: Best practice kinda question"
- Reply: Michael C: "Re: Best practice kinda question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|