0% found this document useful (0 votes)
49 views

MySQL Workbench Forward Engineering SQL Code of Employee Management

This document contains the SQL code to create multiple tables for a company database schema in MySQL. It defines tables for departments, employee details, projects, and relationships between these entities with primary and foreign keys. The tables are created with InnoDB engine for transactions and foreign key support.

Uploaded by

manish
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

MySQL Workbench Forward Engineering SQL Code of Employee Management

This document contains the SQL code to create multiple tables for a company database schema in MySQL. It defines tables for departments, employee details, projects, and relationships between these entities with primary and foreign keys. The tables are created with InnoDB engine for transactions and foreign key support.

Uploaded by

manish
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

-- 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='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ER
ROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

-- -----------------------------------------------------
-- Schema company
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema company
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `company` DEFAULT CHARACTER SET utf8mb4 COLLATE
utf8mb4_0900_ai_ci ;
USE `company` ;

-- -----------------------------------------------------
-- Table `company`.`dept_location`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `company`.`dept_location` (
`Dnumber` INT NOT NULL,
`Dlocation` VARCHAR(19) NOT NULL,
PRIMARY KEY (`Dnumber`, `Dlocation`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

-- -----------------------------------------------------
-- Table `company`.`department`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `company`.`department` (
`Dname` VARCHAR(15) NOT NULL,
`Dnumber` INT NOT NULL,
`Mgr_ssn` CHAR(10) NOT NULL,
`Mgr_start_date` DATE NULL DEFAULT NULL,
`dept_location_Dnumber` INT NOT NULL,
`dept_location_Dlocation` VARCHAR(19) NOT NULL,
PRIMARY KEY (`Dnumber`, `dept_location_Dnumber`, `dept_location_Dlocation`),
INDEX `fk_department_dept_location1_idx` (`dept_location_Dnumber` ASC,
`dept_location_Dlocation` ASC) VISIBLE,
CONSTRAINT `fk_department_dept_location1`
FOREIGN KEY (`dept_location_Dnumber` , `dept_location_Dlocation`)
REFERENCES `company`.`dept_location` (`Dnumber` , `Dlocation`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

-- -----------------------------------------------------
-- Table `company`.`work_on`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `company`.`work_on` (
`Essn` CHAR(10) NOT NULL,
`Pno` INT NOT NULL,
`Hours` DECIMAL(3,3) NOT NULL,
PRIMARY KEY (`Essn`, `Pno`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

-- -----------------------------------------------------
-- Table `company`.`employee`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `company`.`employee` (
`fname` VARCHAR(20) NOT NULL,
`lname` VARCHAR(20) NOT NULL,
`middle` CHAR(1) NULL DEFAULT NULL,
`ssn` CHAR(12) NOT NULL,
`birthDate` DATE NULL DEFAULT NULL,
`Address` VARCHAR(30) NOT NULL,
`Sex` CHAR(1) NULL DEFAULT NULL,
`Salary` DECIMAL(10,0) NOT NULL,
`super_ssn` VARCHAR(12) NULL DEFAULT NULL,
`Dno` INT NOT NULL,
`department_Dnumber` INT NOT NULL,
`work_on_Essn` CHAR(10) NOT NULL,
`work_on_Pno` INT NOT NULL,
PRIMARY KEY (`ssn`, `department_Dnumber`, `work_on_Essn`, `work_on_Pno`),
INDEX `fk_employee_department_idx` (`department_Dnumber` ASC) VISIBLE,
INDEX `fk_employee_work_on1_idx` (`work_on_Essn` ASC, `work_on_Pno` ASC) VISIBLE,
CONSTRAINT `fk_employee_department`
FOREIGN KEY (`department_Dnumber`)
REFERENCES `company`.`department` (`Dnumber`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_employee_work_on1`
FOREIGN KEY (`work_on_Essn` , `work_on_Pno`)
REFERENCES `company`.`work_on` (`Essn` , `Pno`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

-- -----------------------------------------------------
-- Table `company`.`dependent`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `company`.`dependent` (
`Essn` CHAR(10) NOT NULL,
`Dependent_Name` VARCHAR(19) NOT NULL,
`sex` CHAR(1) NULL DEFAULT NULL,
`birthDate` DATE NULL DEFAULT NULL,
`Relationship` VARCHAR(17) NULL DEFAULT NULL,
`employee_ssn` CHAR(12) NOT NULL,
`employee_department_Dnumber` INT NOT NULL,
`employee_work_on_Essn` CHAR(10) NOT NULL,
`employee_work_on_Pno` INT NOT NULL,
PRIMARY KEY (`Essn`, `Dependent_Name`, `employee_ssn`, `employee_department_Dnumber`,
`employee_work_on_Essn`, `employee_work_on_Pno`),
INDEX `fk_dependent_employee1_idx` (`employee_ssn` ASC, `employee_department_Dnumber`
ASC, `employee_work_on_Essn` ASC, `employee_work_on_Pno` ASC) VISIBLE,
CONSTRAINT `fk_dependent_employee1`
FOREIGN KEY (`employee_ssn` , `employee_department_Dnumber` , `employee_work_on_Essn` ,
`employee_work_on_Pno`)
REFERENCES `company`.`employee` (`ssn` , `department_Dnumber` , `work_on_Essn` ,
`work_on_Pno`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

-- -----------------------------------------------------
-- Table `company`.`project`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `company`.`project` (
`Pname` VARCHAR(19) NOT NULL,
`Pnumber` INT NOT NULL,
`Plocation` VARCHAR(17) NULL DEFAULT NULL,
`Dnum` INT NULL DEFAULT NULL,
`department_Dnumber` INT NOT NULL,
`work_on_Essn` CHAR(10) NOT NULL,
`work_on_Pno` INT NOT NULL,
PRIMARY KEY (`Pnumber`, `department_Dnumber`, `work_on_Essn`, `work_on_Pno`),
INDEX `fk_project_department1_idx` (`department_Dnumber` ASC) VISIBLE,
INDEX `fk_project_work_on1_idx` (`work_on_Essn` ASC, `work_on_Pno` ASC) VISIBLE,
CONSTRAINT `fk_project_department1`
FOREIGN KEY (`department_Dnumber`)
REFERENCES `company`.`department` (`Dnumber`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_project_work_on1`
FOREIGN KEY (`work_on_Essn` , `work_on_Pno`)
REFERENCES `company`.`work_on` (`Essn` , `Pno`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

-- -----------------------------------------------------
-- Table `company`.`employee_has_project`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `company`.`employee_has_project` (
`employee_ssn` CHAR(12) NOT NULL,
`employee_department_Dnumber` INT NOT NULL,
`project_Pnumber` INT NOT NULL,
`project_department_Dnumber` INT NOT NULL,
PRIMARY KEY (`employee_ssn`, `employee_department_Dnumber`, `project_Pnumber`,
`project_department_Dnumber`),
INDEX `fk_employee_has_project_project1_idx` (`project_Pnumber` ASC,
`project_department_Dnumber` ASC) VISIBLE,
INDEX `fk_employee_has_project_employee1_idx` (`employee_ssn` ASC,
`employee_department_Dnumber` ASC) VISIBLE,
CONSTRAINT `fk_employee_has_project_employee1`
FOREIGN KEY (`employee_ssn` , `employee_department_Dnumber`)
REFERENCES `company`.`employee` (`ssn` , `department_Dnumber`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_employee_has_project_project1`
FOREIGN KEY (`project_Pnumber` , `project_department_Dnumber`)
REFERENCES `company`.`project` (`Pnumber` , `department_Dnumber`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

You might also like