Working With Commands

Creating New DataBase

-- Create the database if it doesn't exist
CREATE DATABASE IF NOT EXISTS company_db;

-- Show the list of databases
SHOW DATABASES;

-- Use the newly created database
USE company_db;


-- Create the "worker" table
CREATE TABLE worker (
    worker_id INT AUTO_INCREMENT PRIMARY KEY,
    first_name VARCHAR(50) NOT NULL,
    last_name VARCHAR(50) NOT NULL,
    hire_date DATE,
    department VARCHAR(50),
    salary DECIMAL(10, 2),
    manager_id INT,
    CONSTRAINT fk_manager_id FOREIGN KEY (manager_id) REFERENCES worker(worker_id)
);

-- Create the "bonus" table
CREATE TABLE bonus (
    bonus_id INT AUTO_INCREMENT PRIMARY KEY,
    worker_id INT,
    bonus_amount DECIMAL(8, 2),
    bonus_date DATE,
    CONSTRAINT fk_worker_id FOREIGN KEY (worker_id) REFERENCES worker(worker_id)
);

-- Create the "title" table
CREATE TABLE title (
    title_id INT AUTO_INCREMENT PRIMARY KEY,
    worker_id INT,
    job_title VARCHAR(50),
    title_start_date DATE,
    CONSTRAINT fk_worker_id_title FOREIGN KEY (worker_id) REFERENCES worker(worker_id)
);

Populating Data

Bonus Table
Title Table
Worker Table

Last updated

Was this helpful?