Ron A. said:
Chris,
Thanks for the fast reply and your suggestion looks really close to my
needs.
Ron A.,
You're welcome!
I will try to give you some more info on my current database. I am an
Inspector for a company that repairs their own equipment. Each vehicle is
assigned a registration number (example... 02C00055). When a vehicle comes
in for maintenance, a work order is opened and sent to a specific shop with
all the jobs that need to be done. I do outgoing quality control inspections
on the work that was done by the mechanics.
Currently, I use the database to track the QC inspections with Reg No, W/O
No, insp date, who inspected, pass or fail, reject items and who worked on
it. I also created some date queries and reports so I can track individual
performance by showing the number of inspection passed or failed by each
mechanic and fail rate.
I also used check boxes for showing when the vehicle comes in for scheduled
maintenance if it was just a visual, wheel bearing repack/brake inspection
and so on.
It way error in my first post on the relationships... they are one to many.
I hope this helps. I really do appreciate your time and assistance.
Ok, here is my redesign based on your latest description.
Tables:
CREATE TABLE Shops
(ShopID AUTOINCREMENT
,ShopName TEXT(36)
,CONSTRAINT pk_Shops
PRIMARY KEY (ShopID)
)
CREATE TABLE Employees
(EmployeeID AUTOINCREMENT
,ShopID INTEGER NOT NULL
,LastName TEXT(36)
,FirstName TEXT(36)
,Position TEXT(36)
,Section TEXT(36)
,CONSTRAINT pk_Employees
PRIMARY KEY (EmployeeID)
,CONSTRAINT fk_Employees_Shops
FOREIGN KEY (ShopID)
REFERENCES Shops (ShopID)
)
CREATE TABLE Vehicles
(VIN TEXT(17)
,Make TEXT(255)
,Model TEXT(255)
,ManufactureYear CHAR(4)
,[reg no] TEXT(255)
,CONSTRAINT pk_Vehicles
PRIMARY KEY (VIN)
)
CREATE TABLE WorkOrders
(WorkOrderID AUTOINCREMENT
,VIN TEXT(17) NOT NULL
,OpenDate DATETIME NOT NULL
,CloseDate DATETIME
,CONSTRAINT pk_WorkOrders
PRIMARY KEY (WorkOrderID)
,CONSTRAINT fk_WorkOrders_Clients
FOREIGN KEY (VIN)
REFERENCES Vehicles (VIN)
)
CREATE TABLE InspectionTests
(InspectionTestID AUTOINCREMENT
,TestName TEXT(255) NOT NULL
,TestDescription TEXT(255)
,CONSTRAINT pk_InspectionTests
PRIMARY KEY (InspectionTestID)
)
CREATE TABLE InspectionPlans
(InspectionPlanID AUTOINCREMENT
,InspectionName TEXT(255) NOT NULL
,BeginUse DATETIME NOT NULL
,EndUse DATETIME
,CONSTRAINT pk_InspectionPlans
PRIMARY KEY (InspectionPlanID)
)
CREATE TABLE InspectionPlanDetails
(InspectionPlanID INTEGER NOT NULL
,InspectionTestID INTEGER NOT NULL
,BeginUse DATETIME NOT NULL
,EndUse DATETIME
,CONSTRAINT pk_InspectionPlanDetails
PRIMARY KEY (InspectionPlanID, InspectionTestID)
,CONSTRAINT fk_InspectionPlanDetails_InspectionPlans
FOREIGN KEY (InspectionPlanID)
REFERENCES InspectionPlans (InspectionPlanID)
,CONSTRAINT fk_InspectionPlanDetails_InspectionTests
FOREIGN KEY (InspectionTestID)
REFERENCES InspectionTests (InspectionTestID)
)
CREATE TABLE Inspections
(InspectionID AUTOINCREMENT
,WorkOrderID INTEGER NOT NULL
,InspectionPlanID INTEGER NOT NULL
,InspectionStart DATETIME NOT NULL
,InspectionEnd DATETIME
,CONSTRAINT pk_Inspections
PRIMARY KEY (InspectionID)
,CONSTRAINT fk_Inspections_WorkOrders
FOREIGN KEY (WorkOrderID)
REFERENCES WorkOrders (WorkOrderID)
,CONSTRAINT fk_Inspections_InspectionPlans
FOREIGN KEY (InspectionPlanID)
REFERENCES InspectionPlans (InspectionPlanID)
)
CREATE TABLE InspectionDetails
(InspectionID INTEGER NOT NULL
,InspectionTestID INTEGER NOT NULL
,Pass BIT NOT NULL
,Comments TEXT(255)
,CONSTRAINT pk_InspectionDetails
PRIMARY KEY (InspectionID, InspectionTestID)
,CONSTRAINT fk_InspectionDetails_Inspections
FOREIGN KEY (InspectionID)
REFERENCES Inspections (InspectionID)
,CONSTRAINT fk_InspectionDetails_InspectionTests
FOREIGN KEY (InspectionTestID)
REFERENCES InspectionTests (InspectionTestID)
)
CREATE TABLE InspectionEmployees
(InspectionID AUTOINCREMENT
,EmployeeID INTEGER NOT NULL
,CONSTRAINT pk_InspectionEmployees
PRIMARY KEY (InspectionID, EmployeeID)
,CONSTRAINT fk_InspectionEmployees_Inspections
FOREIGN KEY (InspectionID)
REFERENCES Inspections (InspectionID)
,CONSTRAINT fk_InspectionEmployees_Employees
FOREIGN KEY (EmployeeID)
REFERENCES Employees (EmployeeID)
)
Changes:
Clients was changed into Vehicles.
An InspectionTests table was added. It stores information on the
various tests that can be conducted in an Inspection.
An InspectionPlans table was added. There appear to be pre-set things
that are done for any particular inspection. The plans are named
here.
An InspectionPlanDetails table was added. This table collects all the
inspection tests that will be performed in any particular inspection
plan.
Inspections was altered to include the primary key of InspectionPlans.
This way, we know all the tests that will be performed for a certain
inspection.
An InspectionDetails table was added. This table records the results
of each test done in an inspection.
So, four new tables, and two alterations.
With this setup you can ever guaranteeing that each particular
inspection is finished by making sure that an inspection cannot be
finished until its inspection details records match the inspection
plan specified (five tests in the plan, five tests in the details).
Or at least you can issue an error message to a separate "messages"
table that gets printed out later (this is if you enter the computer
data later based on paper records filled out while working . . . I
don't know what your paper/computer/data-entry set up is in your
shop), so that you know that the inspection wasn't properly completed.
But that's a set of questions for the formscoding newsgroup.
Create a new blank database, load and execute the DDL SQL queries,
study the relationships.
Sincerely,
Chris O.