mis621 - lap report

Upload: sajidmahmoodchoudhury

Post on 09-Mar-2016

222 views

Category:

Documents


1 download

DESCRIPTION

Lab Report - SQL

TRANSCRIPT

Lab 2: Work with Dictionary and Create Relational Database (60 pts.) iLAB OVERVIEWScenario and Summary In this lab, you will prepare a Data Dictionary based on the list of elements. Also, your task will be determined the tables, their relationships, primary and foreign keys. Based on this analysis, you will create Database Schema, relational tables, Entity Relational Diagram (ERD), establish connection to your local MySQL Server, create physical database and insert data to the tables.MySQL provides two primary types of file management: dictionary-managed files and MySQL Workbench-managed files. As part of this iLab, you will need to supply some information as to how you would use both of these approaches, and you will have to discuss some of the advantages of each. For Step 3, you need access to your database instance. If you have any difficulties connecting your database instance, let's take error messages, screen shots, descriptions of the situation to the graded threads and work as a team to resolve issues. Now you are ready to proceed. Deliverables Your assignment will be graded based on the following. Assignment Step Description Points

Step 1 Create Data Dictionary for provided elements (Word document) 15

Step 2 Create SCHEMA and database tables in MySQL Workbench15

Step 3 Establish connection to the MySQL Server (screenshots)15

Step 4Insert data to tables using MySQL Workbench15

Total Lab Points 60

For Steps 1, 2, 3 and 4 create a single Word document and include the answers or solutions to all problems. Be sure to label your document and include your name and course number in the heading. Save your document as "yourname_Lab_2.docx." Submit both "yourname_Lab_2.docx" to the Dropbox for this week. iLAB STEPS STEP 1: Create Data Dictionary for provided elements As the DBA for your company, you have decided to install a new version of the MySQL database to replace the current database version being used. The old database has become a constant headache and seems to be causing an overload on the disk drive's I/O channels. Further analysis has also shown that two primary large tables are the main points of access. The new tables will be DEPT, EMPLOYEE, and BONUS. Describe how you plan to compile the Data Dictionary and decide on the tables structure with the new MySQL database. Given list of elements:NNAttribute NameColumn nameData Type

1Employee number (PK)EMPNONUMBER(4)

2Employee first nameEFNAME

3Employee last nameELNAMEVARCHAR2(20)

4Job category (FK)JOBCATEGORYVARCHAR2(4)

5ManagerMGRNUMBER (4)

6Hire dateHIREDATEDATE

7SalarySALNUMBER (7.2)

8CommissionCOMMNUMBER (7.2)

9Department number(FK)DEPTNONUMBER(2)

10Department nameDEPTNAMEVARCHAR2(14)

11LocationLOCVARCHAR2(13)

12Job title JOBTITLEVARCHAR2(20)

13Job description JOBDESCVARCHAR2(20)

Compile Data Dictionary (in alphabetic order):NNAttribute NameColumn nameData TypeData element descriptionTable namePrimary key/ Foreign key indicator (P/F)Not NULLDefault value

1Bonus NumberBONONUMBER(2)Bonus Identification NumberBonuspYES00

1.1Bonus TypeBONUSTYPEVARCHAR2(13)Type of BonusBonusYES

1.2Jab CategoryJOBCATEGORYVARCHAR2(4)Job Category NumberBonusFYESMNGR

2Department numberDEPTNONUMBER(2)Number of DepartmentDept.PYES00

2.1Department NameDEPTNAMEVARCHAR2(14)Name of the DepartmentDept.YESMarketing

2.2LocationLOCVARCHAR2(13)Dept. LocationDept.YES

2.3Employee Number EMPNONUMBER(4)Employee record identification numberEmployeeFYES0000

3Employee Number EMPNONUMBER(4)Employee record identification numberEmployeePYES0000

3.1Employee First NameEFNAMEFirst Name of the employeeEmployeeYESSmith

3.2Employee Last NameELNAMEVARCHAR2(20)Last Name of the employeeEmployeeYESJohn

3.3Hire DateHIREDATEDATEDate Started WorkingEmployeeYES

3.4SalarySALNUMBER (7.2)Employee RemunerationEmployeeYES

3.5CommissionCOMMNUMBER (7.2)Earned CommissionEmployeeNO

3.6Job CategoryJOBCATEGORYVARCHAR2(4)Job Category NumberEmployeeFYESMNGR

4Jab CategoryJOBCATEGORYVARCHAR2(4)Job Category NumberJobPYESMNGR

4.1 Job TitleJOBTITLEVARCHAR2(20)Title of the JobJobYES

4.2Job descriptionJOBDESCVARCHAR2(20)Description of the JobJobYES

4.3Department numberDEPTNONUMBER(2)Number of DepartmentJobFYES00

Place and save your answers in a Word document named "yourname_Lab_2.docx." STEP 2: Create SCHEMA and database tables in MySQL Workbench 2.a Create SCHEMAa) Launch MySQL Workbench;b) Click File and choose New Model;c) Add Diagram: Name: new schema name; d) Press Enter and new SCHEMA will be added;2.b Create tablesa) In Model overview (top part of the screen) Click Add Diagram; Navigation pane shows new schema in Catalog Tree;b) Place a new table on the free part of screen;c) Fill:Table Name:Column Name, Datatype; PK; NN; UQ;BIN; UN; ZF;AI; Default;Press Enterd) Continue to add all tables; 2.c Foreign key creation a) Click on the bottom of the Form Foreign key to establish the reference to parent table;b) Choose the Reference table and Reference column;c) Choose Foreign key options On Update and On Delete; Enter.2.d Save databasea) Choose File on the Toolbar and Save Model as on your folder. Established database are visible on Home page.

STEP 3: Create and configure a new connection to the MySQL ServerPart 1 Create a new connection to the MySQL Servera) Launch to MySQL Workbench Home page;b) To add a connection, click the [+] icon to the right of the MySQL Connections title. This opens the Setup New Connection form: Figure3.1Setup New Connection Form

Important note: The Setup New Connection form features a Configure Server Management button (bottom left) that is required for the MySQL connection to perform tasks that requires shell access to the host. For example, starting/stopping the MySQL instance or editing the configuration file Fill out the connection details and optionally click Configure Server Management to execute the Server Management wizard. Click OK to save the connection. Important All connections opened by MySQL Workbench automatically set the client character set to utf8. Manually changing the client character set, such as using SET NAMES ..., may cause MySQL Workbench to not correctly display the characters. c) New connections are added to the Home page as a tile, and multiple connections may be opened simultaneously in MySQL Workbench. Part 2 Configure a New MySQL Connection a) Click on Local Instance MySQL and enter password;123b) Local Instance MySQL screen appears;c) Click MySQL Workbench Home, click database to be connected;d) EER Diagram screen appears;e) Choose Database on Toolbar and Forward Engineering on scroll menu;f) Forward Engineer to Database screen appears

Set parameters for Connecting to a DBMS:Stored Connection: Select from saved connection settings; Click Next;g) Set Options for Database to be Created appearsSelect DROP objects before each CREATE object;Leave selected Include model attached script; Click Next;

h) Select Objects to Forward Engineer screen appears, enter password again;Select Export MySQL Table Objects and click Next;

i) Review the SQL script to be Executed screen appears for your review and saving to file or copy to Clipboard; Click Next;

j) Forward Engineering Progress screen appears, enter password again;

k) Forward Engineering Progress shows the executed tasks.

l) Click Close.Please add Management, INSTANCE and PERFORMANCE screenshots for the created database to lab Report.

STEP 4: Insert data to tables using MySQL Workbench a) Copy INSERT statements for the given tables into the notepad;-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

-- ------------------------------------------------------- Schema mydb-- -----------------------------------------------------

-- ------------------------------------------------------- Schema mydb-- -----------------------------------------------------CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;USE `mydb` ;

-- ------------------------------------------------------- Table `mydb`.`JOB`-- -----------------------------------------------------DROP TABLE IF EXISTS `mydb`.`JOB` ;

CREATE TABLE IF NOT EXISTS `mydb`.`JOB` ( `JOBCATEGORY` VARCHAR(4) NOT NULL COMMENT '', `JOBTITLE` VARCHAR(20) NULL COMMENT '', `JOBDESC` VARCHAR(20) NULL COMMENT '', `DEPTNO` SMALLINT(6) NULL COMMENT '', PRIMARY KEY (`JOBCATEGORY`) COMMENT '', UNIQUE INDEX `DEPTNO_UNIQUE` (`DEPTNO` ASC) COMMENT '')ENGINE = InnoDB;

-- ------------------------------------------------------- Table `mydb`.`EMPLOYEE`-- -----------------------------------------------------DROP TABLE IF EXISTS `mydb`.`EMPLOYEE` ;

CREATE TABLE IF NOT EXISTS `mydb`.`EMPLOYEE` ( `EMPNO` INT(11) NOT NULL COMMENT '', `EFNAME` VARCHAR(20) NULL COMMENT '', `ELNAME` VARCHAR(20) NULL COMMENT '', `HIREDATE` DATE NULL COMMENT '', `SAL` DECIMAL(10,0) NULL COMMENT '', `COMM` DECIMAL(10,0) NULL COMMENT '', `JOBCATEGORY` VARCHAR(4) NULL COMMENT '', `EMPLOYEE_EMPNO` INT(11) NOT NULL COMMENT '', `JOB_JOBCATEGORY` VARCHAR(4) NOT NULL COMMENT '', PRIMARY KEY (`EMPNO`, `EMPLOYEE_EMPNO`, `JOB_JOBCATEGORY`) COMMENT '', UNIQUE INDEX `JOBCATEGORY_UNIQUE` (`JOBCATEGORY` ASC) COMMENT '', INDEX `fk_EMPLOYEE_EMPLOYEE1_idx` (`EMPLOYEE_EMPNO` ASC) COMMENT '', INDEX `fk_EMPLOYEE_JOB1_idx` (`JOB_JOBCATEGORY` ASC) COMMENT '', CONSTRAINT `fk_EMPLOYEE_EMPLOYEE1` FOREIGN KEY (`EMPLOYEE_EMPNO`) REFERENCES `mydb`.`EMPLOYEE` (`EMPNO`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_EMPLOYEE_JOB1` FOREIGN KEY (`JOB_JOBCATEGORY`) REFERENCES `mydb`.`JOB` (`JOBCATEGORY`) ON DELETE NO ACTION ON UPDATE NO ACTION)ENGINE = InnoDB;

-- ------------------------------------------------------- Table `mydb`.`BONUS`-- -----------------------------------------------------DROP TABLE IF EXISTS `mydb`.`BONUS` ;

CREATE TABLE IF NOT EXISTS `mydb`.`BONUS` ( `BONO` INT(2) NOT NULL COMMENT '', `BONUSTYPE` VARCHAR(20) NULL COMMENT '', `JOBCATEGORY` VARCHAR(4) NOT NULL COMMENT '', `JOB_JOBCATEGORY` VARCHAR(4) NOT NULL COMMENT '', PRIMARY KEY (`BONO`, `JOB_JOBCATEGORY`) COMMENT '', INDEX `fk_BONUS_JOB1_idx` (`JOB_JOBCATEGORY` ASC) COMMENT '', CONSTRAINT `fk_BONUS_JOB1` FOREIGN KEY (`JOB_JOBCATEGORY`) REFERENCES `mydb`.`JOB` (`JOBCATEGORY`) ON DELETE NO ACTION ON UPDATE NO ACTION)ENGINE = InnoDB;

-- ------------------------------------------------------- Table `mydb`.`DEPT`-- -----------------------------------------------------DROP TABLE IF EXISTS `mydb`.`DEPT` ;

CREATE TABLE IF NOT EXISTS `mydb`.`DEPT` ( `DEPTNO` INT(2) NOT NULL COMMENT '', `DEPTNAME` VARCHAR(14) NULL COMMENT '', `LOC` VARCHAR(12) NULL COMMENT '', `EMPNO` INT(4) NULL COMMENT '', `EMPLOYEE_EMPNO` INT(11) NOT NULL COMMENT '', PRIMARY KEY (`DEPTNO`) COMMENT '', UNIQUE INDEX `EMPNO_UNIQUE` (`EMPNO` ASC) COMMENT '', INDEX `fk_DEPT_EMPLOYEE_idx` (`EMPLOYEE_EMPNO` ASC) COMMENT '', CONSTRAINT `fk_DEPT_EMPLOYEE` FOREIGN KEY (`EMPLOYEE_EMPNO`) REFERENCES `mydb`.`EMPLOYEE` (`EMPNO`) ON DELETE NO ACTION ON UPDATE NO ACTION)ENGINE = InnoDB;

SET SQL_MODE=@OLD_SQL_MODE;SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;b) Launch to MySQL Workbench Home page;c) Choose created database instance; enter password;d) New screen appears with the Connection name;e) Choose in Navigator your schemas name;f) Copy script from Notepad to screen Query 1;

g) Highlight executable rows, choose Query on the Toolbar and Execute (All or Selection);

h) Output will display the results of the execution.

Please select counters and rows in database tables and add screenshots to lab Report.1