21
Arrow Plastic 1 Goal: Using what we’ve learned about Arrow Plastic, design a database that is in 3rd normal form that could be used to determine which jobs and molds are run on which machines. CS-530-12: Database Systems & Programming

Arrow Plastics Database Presentation

Embed Size (px)

Citation preview

  1. 1. Arrow Plastic 1 Goal: Using what weve learned about Arrow Plastic, design a database that is in 3rd normal form that could be used to determine which jobs and molds are run on which machines. CS-530-12: Database Systems & Programming
  2. 2. ERD 2
  3. 3. Molds Table Per Steve @ AP, Changed the Injection Mold Type from 1 to 4 INSERT INTO dbo.Lookup_MoldType (MoldType, MoldTypeDescription) VALUES (4, 'Injection Molding') UPDATE dbo.Molds SET MoldType = 4 WHERE MoldType = 1 DELETE FROM dbo.Lookup_MoldType WHERE MoldType = 1 MoldNo was created as an Identity column to ensure data integrity. ArrowMoldNos are the AP and IBM Mold numbers from the Excel spreadsheets To allow for growth, MoldType was created as a tinyint and a corresponding Lookup_ MoldType table was created 3
  4. 4. MoldToProduct Table CREATE TABLE dbo.MoldToProduct (See Picture for Columns & Data Types) ALTER TABLE dbo.MoldToProduct ADD PRIMARY KEY (ProductNo, MoldNo) ALTER TABLE dbo.MoldToProduct ADD CONSTRAINT FK_MoldToProduct_Molds FOREIGN KEY (MoldNo) REFERENCES dbo.Molds (MoldNo) ALTER TABLE dbo.MoldToProduct ADD CONSTRAINT FK_MoldToProduct_Products FOREIGN KEY (ProductNo) REFERENCES dbo.Products (ProductNo) 4
  5. 5. Products Table -- =================================================== -- Author: Michaelene -- Create date: 8 Dec 2014 -- Description: This is to create a Products Table -- for the Arrow Plastics Group Project -- =================================================== USE ArrowPlastics GO CREATE TABLE dbo.Products (ProductNo int NOT NULL, Descr varchar(50) NOT NULL, UOM varchar(15) NULL, Unit_Price money NULL, UPC_no varchar(12) NOT NULL, GTIN_no varchar(14) NOT NULL, PRIMARY KEY (ProductNo) ) GO 5
  6. 6. Mold_Matrix Table 6 This table holds the information of what molds could run on which machines Primary Key: MoldNo & MachineNo (Composite) Foreign Key: References from Molds & Machines Tables SAMPLE DATA:
  7. 7. Machines Table 7
  8. 8. Product_Schedule Table --Create Product Schedule Table USE [ArrowPlastics] GO CREATE TABLE [Product_Schedule] (ScheduleNo int identity(1,1) NOT NULL, MoldNo int NOT NULL, OrderNo int NOT NULL, ProductNo int NOT NUll, StartTimeStamp datetime NULL, EndTimeStamp datetime NULL, RunningIndicator bit NULL, PRIMARY KEY (ScheduleNo)); --Add Foreign Key from Product Schedule to Products Table USE ArrowPlastics GO ALTER TABLE Product_Schedule WITH NOCHECK ADD CONSTRAINT FK_Product_Schedule_Products FOREIGN KEY(ProductNo) REFERENCES [Products](ProductNo) 8
  9. 9. Orders Table CREATE TABLE [dbo].[Orders]( [OrderNo] [int] IDENTITY(1,1) NOT NULL, [OrderDate] [date] NOT NULL, [ShipDate] [date] NOT NULL, [OrderTotal] [money] NULL, [CustomerNo] [int] NOT NULL, [ShippingId] [tinyint] NOT NULL, CONSTRAINT [PK_Orders] PRIMARY KEY CLUSTERED ([OrderNo] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] GO ALTER TABLE [dbo].[Orders] WITH NOCHECK ADD CONSTRAINT [FK_Orders] FOREIGN KEY([CustomerNo]) REFERENCES [dbo].[Customers] ([CustomerNo]) GO ALTER TABLE [dbo].[Orders] CHECK CONSTRAINT [FK_Orders] GO 9
  10. 10. Customers Table -- =================================================== -- Author: Jimmy Koumoundouros -- Create date: 24 Nov 2014 -- Description: This is to create a Customers Table -- for the Arrow Plastics Group Project -- =================================================== USE ArrowPlastics GO CREATE TABLE Customers ( CustomerNo int IDENTITY(1,1) NOT NULL, CustomerFirstName varchar(50) NOT NULL, CustomerLastName varchar(50) NOT NULL, CustomerPhone varchar(15) NOT NULL, CustomerEmail varchar(30) NOT NULL, CustomerAddressLine1 varchar(100) NOT NULL, CustomerAddressLine2 varchar(100) NULL, CustomerCity varchar(30) NOT NULL, CustomerState char(3) NOT NULL, CustomerZipCode int NOT NULL, CustomerCountry varchar(30) NOT NULL PRIMARY KEY (CustomerNo) ) GO 10
  11. 11. GetMachineByMold Procedure Execute Code Results 11
  12. 12. GetMachineByJobCount Procedure Execute Code Results 12 The design of this procedure will allow AP to be able to see the number of molds that each machine can run. Example: Which machines can run more than 50 molds?
  13. 13. GetMachinesWithNoMolds Procedure GetMachinesWithNoMolds USE ArrowPlastics GO Create Procedure GetMachinesWithNoMolds AS SELECT MoldMachineMatrix.Machineno AS 'Machine Number',Machines.Description AS 'Machine Name' FROM MoldMachineMatrix JOIN Machines ON MoldMachineMatrix.MachineNo = Machines.MachineNo WHERE MoldMachineMatrix.MoldNo IS NULL EXECUTE GetMachinesWithNoMolds GO (There are no machines that have no molds in our sample data.) 13
  14. 14. GetProductSchedulesByProduct Procedure 14
  15. 15. GetProductSchedulesAfter Procedure Execute Code Results 15
  16. 16. GetProductScheduleBefore Procedure Execute Code Results 16
  17. 17. GetProductSchedulesBetween Procedure Execute Code Results 17
  18. 18. GetCurrentlyRunningSchedules Procedure Procedure Code USE [ArrowPlastics] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [DBO].[GetCurrentlyRunningSchedules] AS BEGIN SELECT ps.ScheduleNo, ps.StartTimeStamp, ps.EndTimeStamp, p.descr AS 'Product Name' From Product_Schedule ps Join Products p ON p. ProductNo = ps. ProductNo Where RunningIndicator = '1' END GO Procedure Execute USE [ArrowPlastics] GO EXECUTE GetCurrentlyRunningSchedules Results From Runningindicator 1 or 0 18
  19. 19. GetSummaryOfAllJobsRunning Procedure /****** Object: StoredProcedure [dbo].[GetSummaryOfAllJobsRunning] Script Date: 12/7/2014 11:58:43 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[GetSummaryOfAllJobsRunning] AS BEGIN SELECT ps.ScheduleNo AS 'Schedule#', ps.MoldNo AS 'Mold#', ps.OrderNo AS 'Order#', ps.ProductNo AS 'Product#', p.Descr AS 'Desription', ps.StartTimeStamp AS 'Job Start Time', ps.EndTimeStamp AS 'Expected Job End Time' FROM Product_Schedule ps JOIN Products p ON p.ProductNo = ps.ProductNo WHERE RunningIndicator = '1' END GO -- Execute the Stored Procedure Code USE ArrowPlastics GO EXECUTE GetSummaryOfAllJobsRunning 19
  20. 20. GetJobSummaryByMachine Procedure 20 CREATE PROCEDURE GetJobSummaryByMachine @InputMachineNo varchar(10) AS BEGIN SELECT DISTINCT MoldMachineMatrix.MachineNo, ScheduleNo, MoldMachineMatrix.MoldNo, Products.ProductNo, Product_Schedule.OrderNo FROM Product_Schedule INNER JOIN Products ON Product_Schedule.ProductNo = Products.ProductNo INNER JOIN MoldMachineMatrix ON Product_Schedule.MoldNo = MoldMachineMatrix.MoldNo WHERE MoldMachineMatrix.MachineNo = @InputMachineNo END GO -- Execute the Stored Procedure Code DECLARE @InputMachineNo varchar(10) EXECUTE GetJobSummaryByMachine '10' EXECUTE GetJobSummaryByMachine '2' EXECUTE GetJobSummaryByMachine '20' EXECUTE GetJobSummaryByMachine '7a'
  21. 21. Contributors Brian Adamson Shoeb Ahmed Charlotte Alessandri Tara Comerci Saravanakumar Dwarakan Rod Gonzales Stewart Goodman Isaac Johnson 21 Jimmy Koumoundouros Ubeydullah Kulunkoglu Robert Mayer Abigail Powers Safwan Sawaie Michaelene Stalla Brett Stockmeier