GamerCentral Christian Bauer Assigned: 1/12/2012 Due: 4/26/2012 1 Table of Contents: Introduction and Background --- Pg 3 External Schema of the System --- Pg 4 Entity - Relationship Diagram --- Pg 5 Un-Normalized Relational Model --- Pg 6 Normalization Process --- Pg 7 Normalized Model --- Pg 8 Data Dictionary --- Pg 9 Create Statements --- Pg 14 Insert Statements --- Pg 22 View --- Pg 30 Five Types of SQL Queries --- Pg 32 Update Statements --- Pg 37 Glossary --- Pg 41 References --- Pg 42 2 Introduction and background of domain: Games Shopping System is a system that allows customers to search for available games based on their favorite genre. The games are sold by the most recent release date to the oldest. The system also shows the ratings for parents to see what game may be appropriate for their children. Shoppers can create a wish list of what items they want and the system will send a notification to when the game comes out or on sale. Games can be in different genres and ratings. Wikipedia and ESRB. These genres and ratings can be: First person shooter Third person shooter Action Adventure Role playing Strategy Simulation Sports EC for early childhood 3 and older E for everyone E 10+ for 10 and older T for teen 13 and older M for mature 17 and older AO for adults only 18 and older 3 A game is a form of entertainment for most people. It can be a social outlet to talk to other gamers while playing a game. Gaming also helps kids becomes multitaskers and may lead to technical careers. External Schema: GamerCentral contains the information of the Company, Employees, Customers and Products. Company has a company name, company id, established date, street, city, state and zipcode. Employees are identified by their id, last name, first name, designation, street, city, state, phone number and zipcode. Customers are identified by their last name, first name, street, city, state and zipcode. Products contain the id, name, category, price and weight. General sentence GamerCentral is an online system which helps people in selecting games which can be selected based on the genre of game. The user will be impressed with purchased game or games that they buy. Sentence about Company Company takes care of the employees, customers and the products. The company has a company name, company id, established date, street, city, state and zipcode. Sentence about Employees Employees are the ones who work under the Company. Employees are identified by their id, last name, first name, SSN, street, city, state and zipcode. Sentence about Customers Customers are the ones who purchase the products from the dealers. Customers are identified by their last name, first name, street, city, state and zipcode. Sentence about Product Products are those which are for customers based on the genre of games and are divided by the id, name, category, price and weight. 4 E-R Diagram: Cust_last Cust_First category name id name Street price state city Customer weight Phone number products name id 1 zipcode 1 N has Company N N manages street id Established date city has zipcode SSN state 1 first employees street name last city state zipcode 5 Un-Normalized model: 6 Cust_ID Comp_ID Cust_Fname Cust_Lname SSN Cust_Phone Cust_Street Cust_City Cust_State Cust_Zip Customer numeric(20) <pk> not null numeric(20) <fk> not null varchar(20) null varchar(20) null numeric(20) not null numeric(20) null varchar(20) null varchar(20) null varchar(20) null varchar(20) null Comp_ID=Comp_ID 1:N Company Comp_ID numeric(20) <pk> not null Comp_Name varchar(20) null Est_Date datetime null Comp_Street varchar(20) null Comp_City varchar(20) null Comp_State varchar(20) null Comp_Zip varchar(20) null Comp_ID=Comp_ID 1:N Product Prod_ID numeric(20) <pk> not null Comp_ID numeric(20) <fk> not null Prod_Name varchar(20) null Prod_Category varchar(20) null Prod_Price varchar(20) null Prod_Weight varchar(20) null Comp_ID=Comp_ID 1:N Emp_ID Comp_ID Emp_Fname Emp_Lname SSN Emp_Street Emp_City Emp_State Emp_Zip Employee numeric(20) <pk> not null numeric(20) <fk> not null varchar(20) null varchar(20) null numeric(20) not null varchar(20) null varchar(20) null varchar(20) null varchar(20) null 7 Normalization Process: For normalizing this model I have added an Address table. Normalization is a systematic way of ensuring that a database structure is suitable for general-purpose querying and free of certain undesirable characteristics that could lead to a loss of data integrity. The customer, employee, and company tables have information such as Street, City, State and Zip. I have created an address table in the normalized model that holds the information, Street, City, State, Zip. For this table I have made Address_ID as the primary key and included this in the Employee, Customer and Company tables as the foreign key. By doing this I was able to reduce a lot of redundancy. I also added a Code table which contains the Address Types, Designation of the Employee, Product Category and Shipping Method. These values are maintained in the Address, Employee and Product tables and connected using the Code_Id to the respective tables. 8 Normalized model: Code numeric(20) <pk> not null numeric(20) not null varchar(20) null varchar(20) null Code_ID Code_Type Code_Desc ShortDesc Code_ID=Code_Type 0:N Code_ID=Emp_Desi 1:1 Address_ID=Address_ID Cust_ID Comp_ID Address_ID Cust_Fname Cust_Lname SSN Cust_Phone Customer numeric(20) numeric(20) numeric(20) varchar(20) varchar(20) numeric(20) numeric(20) <pk> not null <fk1> not null <fk2> not null null null not null null Code_ID=Add_Type 1:1 1:1 Address Address_ID numeric(20) <pk> Add_Type numeric(20) <fk> Street varchar(20) City varchar(20) State varchar(20) Zip varchar(20) 1:1 not null not null null null null null Address_ID=Address_ID 1:1 Address_ID=Address_ID 1:N Comp_ID=Comp_ID 1:N Comp_ID=Comp_ID Comp_ID Address_ID Comp_Name Est_Date Company numeric(20) <pk> not null numeric(20) <fk> not null varchar(20) null datetime null Emp_ID Comp_ID Address_ID Emp_Fname Emp_Lname SSN Emp_Type Employee numeric(20) numeric(20) numeric(20) varchar(20) varchar(20) numeric(20) numeric(20) <pk> not null <fk1> not null <fk2> not null null null not null <fk3> not null 1:N Comp_ID=Comp_ID Prod_ID Comp_ID Prod_Name Prod_Category Prod_Price Prod_Weight Product numeric(20) <pk> not null numeric(20) <fk> not null varchar(20) null varchar(20) null varchar(20) null varchar(20) null 9 Data dictionary: AddressTable Name DataType Value set (Domain) Min Cardinality Max Cardinality Description Address_Id numeric(20) Unique Integer >=0 1 1 Primary key Address_Type varchar(20) Character string 1 1 Address type Street varchar(20) Character string 0 1 Street name City varchar(20) Character string 0 1 City name State varchar(20) Character string 0 1 State name Zip varchar(20) Unique Character string 0 1 Zip code of the place Company table: Name DataType Domain Min Cardinalit y Max Cardinality Description Comp_Id numeric(20) Unique Integer >=0 1 1 Primary key 10 Comp_Name varchar(20) Character string 1 1 Company name Est_Date Date Sysdate 1 1 Established date of the company Address_Id numeric(20) Unique Integer >=0 1 1 Foreign key Customer table: Name DataType Domain Min Cardinality Max Cardinality Description Cust_Id Numeric(20) Unique Integer >=0 1 1 Primary key Comp_Id numeric(20) Unique Integer >=0 1 1 Foreign Key Cust_Fname varchar(20) Character string 1 1 Customer First name Cust_Lname varchar(20) Character string 1 1 Customer Last name SSN Numeric(20) Unique Integer >=0 1 1 Customer SSN Cust_Phone varchar(20) Character string 1 N Customer Phone Address_Id Numeric(20) Unique Integer >=0 1 1 Foreign key Domain Min Cardinality Max Cardinality Description Employee table: Name DataType 11 Emp_Id Numeric(20) Unique Integer >=0 1 1 Primary key Comp_Id numeric(20) Unique Integer >=0 1 1 Foreign Key Emp_Fname varchar(20) Character string 1 1 Employee First name Emp_Lname varchar(20) Character string 1 1 Employee Last name SSN Numeric(20) Unique Integer >=0 1 1 Employee SSN Emp_Desi varchar(20) Character string 1 1 Employeee Designation Address_Id Numeric(20) Unique Integer >=0 1 1 Foreign key Name DataType Domain Min cardinality Max Cardinality Description Prod_Id Numeric(20) Unique Integer >=0 1 1 Primary key Comp_Id Numeric(20) Unique Integer >=0 1 1 Primary key Prod_Name varchar(20) Character string 1 1 Product Name Prod_Category varchar(20) Character string 1 N Product Category Prod_Price varchar(20) Character string 1 1 Product Price Prod_Weight varchar(20) Character 1 1 Product Weight Product table: 12 string Code table: Name DataType Min Cardinality Max Cardinality Description Unique Integer >=0 1 1 Synthetic Primary key Value set (Domain) Code_ID Numeric(10) (Name of the sequence: Seq_Code_Id) Code_Type Numeric(10) Any integer >0 1 1 Type of the code Code_Desc Varchar(30) Character string 0 1 Full description of the code ShortDesc Varchar(10) Character string 1 1 The short representation of code description The values for the code table: Code_ID Code_Type Description Short_Description 1 1 To set a code type TypeCode 2 1 For the type of address to show Add_Type 3 1 Designation of the employee Emp_Desi 4 1 Category of the product Prod_Category 5 2 Company Address Company 6 2 Employee Address Employee 13 7 2 Customer Address Customer 8 3 Employee Designation as Manager Manager 9 3 Employee Designation as Cashier Cashier 10 4 First Person shooter fps 11 4 Strategy rts 12 4 Role-playing rpg 13 4 action action 14 4 adventure adventure 15 4 sports sports 16 4 racing racing 14 Create statements: Creating Sequences CREATE Sequence Seq_Code_ID Increment by 1 Start with 1 nocache; CREATE Sequence Seq_Customer_ID Increment by 1 Start with 1 nocache; CREATE Sequence Seq_Company_ID Increment by 1 Start with 1 nocache; CREATE Sequence Seq_Employee_ID Increment by 1 Start with 1 nocache; CREATE Sequence Seq_Product_ID Increment by 1 Start with 1 nocache; CREATE Sequence Seq_Address_ID Increment by 1 Start with 1 nocache; 15 Creating Tables Creating Code table CREATE TABLE Code ( Code_ID NUMBER (20) not null, Code_Type NUMBER (20) not null, Description VARCHAR (20) null, Short_Description VARCHAR (20) not null, Constraint PK_CodVal PRIMARY KEY (Code_ID), 16 Constraint FK_CodType FOREIGN KEY (Code_Type) references Code (Code_ID) ); Creating Address table CREATE TABLE Address ( Address_ID NUMBER (20) not null, Add_Type NUMBER (20) not null, Street VARCHAR (20) null, City VARCHAR (20) null, State VARCHAR (20) null, 17 Zip VARCHAR (20) null, Constraint PK_Addresses PRIMARY KEY (Address_ID), Constraint FK_AddressesType FOREIGN KEY (Add_Type) references Code(Code_ID) ); Creating Company Table CREATE TABLE Company ( Comp_ID NUMBER (20) not null, Address_ID NUMBER (20) not null, 18 Comp_Name VARCHAR (20) null, Est_date DATE null, Constraint PK_Compan PRIMARY KEY (Comp_ID), Constraint FK_Addr FOREIGN KEY (Address_ID) references Address(Address_ID) ); Creating Customer Table CREATE TABLE Customer ( Cust_ID NUMBER (20) not null, 19 Comp_ID NUMBER (20) not null, Address_ID NUMBER (20) not null, Cust_Fname VARCHAR (20) null, Cust_Lname VARCHAR (20) null, SSN NUMERIC (20) null, Cust_Phone NUMERIC (20) null, Constraint PK_customerin PRIMARY KEY (Cust_ID), Constraint FK_Company_cust FOREIGN KEY (Comp_ID) references Company(Comp_ID), Constraint FK_Addr_Cust FOREIGN KEY (Address_ID) references Address(Address_ID) ); 20 Creating product Table CREATE TABLE Product ( Prod_ID NUMBER (20) not null, Comp_ID NUMBER (20) not null, Prod_Name VARCHAR (20) null, Prod_Category VARCHAR (20) null, Prod_Price NUMBER (20) null, Prod_Weight VARCHAR (20) null, Constraint PK_ProductGift PRIMARY KEY (Prod_ID), Constraint FK_CompanyGift FOREIGN KEY (Comp_ID) references Company (Comp_ID) ); 21 Creating Employee Table CREATE TABLE Employee ( Emp_ID Comp_ID Address_ID NUMBER (20) not null, NUMBER (20) NUMBER (20) not null, not null, Emp_Fname VARCHAR (20) null, Emp_Lname VARCHAR (20) null, SSN Emp_Desi NUMERIC (20) NUMERIC (20) null, not null, 22 Constraint PK_Employer PRIMARY KEY (Emp_ID), Constraint FK_Company FOREIGN KEY (Comp_ID) references Company(Comp_ID), Constraint FK_Address FOREIGN KEY (Address_ID) references Address(Address_ID), Constraint FK_Designation FOREIGN KEY (Emp_Desi) references Code(Code_ID) ); Insert code statements INSERT INTO code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Code_ID_Seq.NextVal, 1, 'code_type', 'TypeCode' ); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 1, 'address_type', 'Add_Type'); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 1, 'employee_designation', 'Emp_Designation' ); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 1, 'product_category', 'Prod_Cat'); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 2, 'company address', 'Comp_Addr' ); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 2, 'employee address', 'Emp_Addr' ); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 2, 'customer address', 'Cust_Addr' ); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 3, 'manager', 'Manager' ); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 3, 'cashier', 'Cashier' ); 23 INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 4, 'First Person Shooter', 'FPS' ); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 4, 'Real time strategy', 'RTS' ); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 4, 'Role playing game', 'RPG' ); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 4, 'action', 'ACTION' ); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 4, 'adventure', 'ADVENTURE' ); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 4, 'sports', 'SPORTS' ); INSERT INTO Code (CODE_ID, CODE_TYPE, CODE_DESC, SHORTDESC) VALUES ( Seq_Code_ID.NextVal, 4, 'racing', 'RACING' ); 24 Address insert statements INSERT INTO Address Values ( Seq_Address_ID.NextVal, 2, 'Rockhill Road', 'Kansas City', 'MO', '64110' ); INSERT INTO Address Values ( Seq_Address_ID.NextVal, 2, 'Charlotte Street', 'Kansas City', 'MO', '64108' ); INSERT INTO Address Values ( Seq_Address_ID.NextVal, 2, 'NW plaza circle', 'Kansas City', 'MO', '64153' ); INSERT INTO Address Values ( Seq_Address_ID.NextVal, 2, 'Canvasback Drive', 'Suisun City', 'CA', '94585' ); 25 Company insert statements INSERT INTO Company Values ( Seq_Company_ID.NextVal, 1 , ’Games R Us’, ’21 Feb 2008’); INSERT INTO Company Values ( Seq_Company_ID.NextVal, 2 , ‘ We Are Gamers‘, ’22 Mar 2006’); INSERT INTO Company Values ( Seq_Company_ID.NextVal, 3 , ’Gamestop’, ’2 Feb 2005’); INSERT INTO Company Values ( Seq_Company_ID.NextVal, 4 , ’Steam’, ’11 Jan 2007’); 26 Customer insert statements INSERT INTO Customer Values ( Seq_Customer_ID.NextVal, 1, 1 , ‘Christian’, ’Bauer’, ’11111’, ’8161234567’); INSERT INTO Customer Values ( Seq_Customer_ID.NextVal, 2, 2 , ‘Kelly’, ’Kerns’, ’23456’, ’9132324444’); INSERT INTO Customer Values ( Seq_Customer_ID.NextVal, 1, 3 , ‘Mike’, ’Jones’, ’22222’, ’7075673456’); INSERT INTO Customer Values ( Seq_Customer_ID.NextVal, 1, 4 , ‘John’, ’Smith’, ’213456’, ’4175324576’); 27 Employee insert statements INSERT INTO Employee Values ( Seq_Employee_ID.NextVal, 1, 1 , 'Bob', 'Smith', '12345', 9); INSERT INTO Employee Values ( Seq_Employee_ID.NextVal, 1, 2 , 'Jerry', 'Springer', '23234', 10); INSERT INTO Employee Values ( Seq_Employee_ID.NextVal, 2, 3 , 'John', 'Maury', '212456', 9); INSERT INTO Employee Values ( Seq_Employee_ID.NextVal, 3, 2 , 'Rikki', 'Lake', '212323', 10); INSERT INTO Employee Values ( Seq_Employee_ID.NextVal, 4, 4, 'Rebbecca', 'Foster', '24452', 9); 28 product insert statements INSERT INTO Product Values ( Seq_Product_ID.NextVal, 1, ‘Fallout’, 13, ’1000’, ’156’); INSERT INTO Product Values ( Seq_Product_ID.NextVal, 2, ‘MLB2k12’, 15, ’1200’, ’170’); INSERT INTO Product Values ( Seq_Product_ID.NextVal, 1, ‘Gran Turismo 4’, 16, ’1350’, ’163’); INSERT INTO Product Values ( Seq_Product_ID.NextVal, 3, ‘Final Fantasy 13’, 12, ’1000’, ’156’); INSERT INTO Product Values ( Seq_Product_ID.NextVal, 3, ‘Kessen 3’, 11, ’1000’, ’156’); INSERT INTO Product Values ( Seq_Product_ID.NextVal, 3, ‘Resistance 3’, 10, ’1000’, ’156’,); 29 30 Creating a view This view will show the customers and the games they will want, which can help with marketing. CREATE VIEW PRODUCTDETAILS AS SELECT C.Cust_FName, P.Prod_ID, P.Prod_Name, C.Cust_phone FROM Customer C, Product P; 31 32 Queries Select sum(Prod_Price) "Price for game", count(Comp_ID) "Number of Products" from Product group by Prod_Price having Sum(Comp_ID)>0; 33 Select Prod_ID, Prod_Name, Prod_Category from Product where Prod_ID IN(select Prod_ID from Product where Comp_ID=(select Comp_ID from Product where Comp_ID=2)); 34 SELECT ad.Street, ad.City, ad.State, ad.Zip, C.Cust_ID "Customer Id", C.Cust_FName "FirstName", C.Cust_LName "LastName", C.SSN "SSN number" FROM Address ad LEFT OUTER JOIN Customer C ON ad.Address_ID = C.Address_ID; 35 SELECT ad.Street, ad.City, ad.State, ad.Zip, e.Emp_ID "Employee Id", e.Emp_FName "FirstName", e.Emp_LName "LastName", e.SSN "SSN number" FROM Address ad LEFT OUTER JOIN Employee e ON ad.Address_ID = e.Address_ID; 36 Select street, city, state,zip from Address ad INNER JOIN Employee e ON ad.Address_id=e.Address_id; 37 Update statements update Product set Prod_Price = 2000 where Prod_ID=3; 38 39 update Product set Prod_name = 'MLB2k13' where Prod_ID=3; 40 41 Glossary: 1. Company: A number of individuals assembled or associated together. 2. Customer: Is the buyer or user of the paid products of an individual or organization, mostly called the supplier or seller. 3. Product: A thing produced by labor. 4. Employee: Technically productive enterprises in a particular field. 42 References: http://www.sa-academy.org/atf/cf/%7B6bc3c885-b60d-4891-96ff08fa2146034d%7D/POSITIVES%20OF%20GAMING%20OUR%20KIDS%20MAG%20JULY%2009.P DF http://www.esrb.org/ratings/ratings_guide.jsp http://en.wikipedia.org/wiki/Video_game_genres 43 Statement: I, Christian Bauer hereby declare that all the work done for this project is of my own except as noted in the provided references and has no unreferenced information included. 44 Signature Date: 4/26/2012 45