arrowplastics_create tables

5
-- ============================================================== -- Creating a database called ArrowPlastics using T-SQL -- ============================================================== CREATE DATABASE ArrowPlastics ON PRIMARY ( NAME = N'ArrowPlastics', FILENAME = N'C:\Program Files\Microsoft SQL Server\ MSSQL12.SQLEXPRESS\MSSQL\DATA\ArrowPlastics.mdf' , SIZE = 10MB , MAXSIZE = 20MB, FILEGROWTH = 1MB ) LOG ON ( NAME = N'ArrowPlastics_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\ MSSQL12.SQLEXPRESS\MSSQL\DATA\ArrowPlastics_log.ldf' , SIZE = 10MB , MAXSIZE = 20MB , FILEGROWTH = 1MB) COLLATE SQL_Latin1_General_CP1_CI_AS GO -- =================================================== -- Author: Jimmy Koumoundouros -- Create date: 17 Jan 2015 -- Description: This is to create a Molds Table -- for the Arrow Plastics Group Project -- =================================================== USE ArrowPlastics GO CREATE TABLE Molds ( MoldNo int IDENTITY(1,1) NOT NULL, ArrowMoldNo varchar(10) NOT NULL, MoldDescription varchar(50) NULL, Cavaties smallint NULL, MoldPPH smallint NOT NULL, MoldType tinyint NOT NULL PRIMARY KEY (MoldNo) ) GO -- =================================================== -- 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,

Upload: jimmy-koumoundouros

Post on 18-Aug-2015

64 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ArrowPlastics_Create Tables

-- ==============================================================-- Creating a database called ArrowPlastics using T-SQL-- ==============================================================

CREATE DATABASE ArrowPlastics ON PRIMARY( NAME = N'ArrowPlastics', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\ArrowPlastics.mdf' , SIZE = 10MB , MAXSIZE = 20MB, FILEGROWTH = 1MB ) LOG ON( NAME = N'ArrowPlastics_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\ArrowPlastics_log.ldf' , SIZE = 10MB , MAXSIZE = 20MB , FILEGROWTH = 1MB) COLLATE SQL_Latin1_General_CP1_CI_ASGO

-- ===================================================-- Author: Jimmy Koumoundouros-- Create date: 17 Jan 2015-- Description: This is to create a Molds Table-- for the Arrow Plastics Group Project-- ===================================================

USE ArrowPlasticsGO

CREATE TABLE Molds(

MoldNo int IDENTITY(1,1) NOT NULL, ArrowMoldNo varchar(10) NOT NULL,MoldDescription varchar(50) NULL,Cavaties smallint NULL,MoldPPH smallint NOT NULL,MoldType tinyint NOT NULLPRIMARY KEY (MoldNo)

)GO

-- ===================================================-- Author: Jimmy Koumoundouros-- Create date: 24 Nov 2014-- Description: This is to create a Customers Table-- for the Arrow Plastics Group Project-- ===================================================

USE ArrowPlasticsGO

CREATE TABLE Customers(

CustomerNo int IDENTITY(1,1) NOT NULL, CustomerFirstName varchar(50) NOT NULL,CustomerLastName varchar(50) NOT NULL,

Page 2: ArrowPlastics_Create Tables

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 NULLPRIMARY KEY (CustomerNo)

)GO

-- ===================================================-- Author: Abigail Powers-- Create date: 17 Jan 2015-- Description: This is to create an Orders Table-- for the Arrow Plastics Group Project-- ===================================================

USE ArrowPlasticsGOCREATE 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]GOALTER TABLE [dbo].[Orders] WITH NOCHECK ADD CONSTRAINT [FK_Orders] FOREIGN KEY([CustomerNo])REFERENCES [dbo].[Customers] ([CustomerNo])GOALTER TABLE [dbo].[Orders] CHECK CONSTRAINT [FK_Orders]GO

-- ===================================================-- Author: Michaelene Stalla-- Create date: 8 Dec 2014-- Description: This is to create a Products Table-- for the Arrow Plastics Group Project-- ===================================================

USE ArrowPlasticsGO

CREATE TABLE Products(

ProductNo int NOT NULL,Descr varchar(50) NOT NULL,

Page 3: ArrowPlastics_Create Tables

UOM varchar(15) NULL,Unit_Price money NULL,UPC_no varchar(12) NOT NULL,GTIN_no varchar(14) NOT NULL,OrderNo int NULL,PRIMARY KEY (ProductNo)

)GO

-- ===================================================-- Author: Jimmy Koumoundouros-- Create date: 17 Jan 2015-- Description: This is to create a MoldToProduct Table-- for the Arrow Plastics Group Project-- ===================================================

USE ArrowPlasticsGO

CREATE TABLE MoldToProduct(

MoldNo int IDENTITY(1,1) NOT NULL, ProductNo int NOT NULL

)GO

ALTER TABLE MoldToProductADD PRIMARY KEY (ProductNo, MoldNo)

ALTER TABLE MoldToProductADD CONSTRAINT FK_MoldToProduct_MoldsFOREIGN KEY (MoldNo)REFERENCES Molds (MoldNo)

ALTER TABLE MoldToProductADD CONSTRAINT FK_MoldToProduct_ProductsFOREIGN KEY (ProductNo)REFERENCES Products (ProductNo)

-- ===================================================-- Author: Ubeydullah Kulunkoglu-- Create date: 17 Jan 2015-- Description: This is to create a Machines Table-- for the Arrow Plastics Group Project-- ===================================================

USE ArrowPlasticsGO

CREATE TABLE Machines(

MachineNo varchar(10) NOT NULL,Description varchar(120) NOT NULL,NoOfJobs int NOT NULL,

Page 4: ArrowPlastics_Create Tables

PRIMARY KEY (MachineNo))GO

-- ===================================================-- Author: Jimmy Koumoundouros-- Create date: 17 Jan 2015-- Description: This is to create a MoldMatrix Table-- for the Arrow Plastics Group Project-- ===================================================

USE ArrowPlasticsGO

CREATE TABLE MoldMatrix(

MoldNo int IDENTITY(1,1) NOT NULL, MachineNo varchar(10) NOT NULL

)GO

ALTER TABLE MoldMatrixADD PRIMARY KEY (MoldNo, MachineNo)

ALTER TABLE MoldMatrixADD CONSTRAINT FK_MoldMatrix_MoldNoFOREIGN KEY (MoldNo)REFERENCES Molds (MoldNo)

ALTER TABLE MoldMatrixADD CONSTRAINT FK_MoldMatrix_MachineNoFOREIGN KEY (MachineNo)REFERENCES Machines (MachineNo)

--Create Product Schedule Table

USE [ArrowPlastics]GOCREATE TABLE [Product_Schedule]

(ScheduleNo int 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 ArrowPlasticsGOALTER TABLE Product_Schedule

Page 5: ArrowPlastics_Create Tables

WITH NOCHECKADD CONSTRAINT FK_Product_Schedule_ProductsFOREIGN KEY(ProductNo)REFERENCES [Products](ProductNo)