💾
Welcome to DataGenesis !
  • 🚀 Welcome to the Database Management System Playground! 📊💾
  • Basics of DBMS
    • Database Management System
    • DBMS V/S File System
    • DBMS Architectures
    • Tier 3 Architecture / Three Schema Architecture
  • E-R Data Model
    • Basics of E-R Model
    • Attributes in E-R Model
    • Null Values
    • Strong & Weak Entities
    • Relationship Constraints
    • Recursive Relationships
    • E-R Diagrams
    • Extended E-R Model
  • Relational Model
    • Relational Model
    • Facts About Relational Model
    • Types of Keys in Relational Model
    • Integrity Constraints
    • Anomalies in Relational Model
  • Transform - ER Model to Relational Model
    • Mapping from ER Model to Relational Model
  • SQL - Structured Query Language
    • SQL
    • CRUD Operations
    • Data Types
    • Type of Commands in SQL
    • Working With Commands
    • Data Retrieval Commands
  • Normalisation
    • Functional Dependencies
    • Armstrong's Axioms
    • Multivalued Dependency
    • 1 Normal Form
    • 2 Normal Form
    • 3 Normal Form
    • Boyce-Codd Normal Form (BCNF)
    • 4 Normal Form
    • 5 Normal Form
    • Lossless Decomposition, Lossless Join ,and Dependency Preserving Decomposition, Denormalization
  • Concurrency Control
    • Transactions & Concurrency
    • Scheduling of Transactions
    • Problems & Strategies in Concurrency Control
    • Transaction & ACID Properties
    • How to implement ACID Properties
    • Atomicity Techniques
    • Durability Techniques
    • Implementing Locking in DBMS
    • Concurrency Control Protocols
      • Two Phase Locking
      • Timestamp Ordering
      • Multi Version Concurrency Control Techniques
    • Starvation in DBMS
    • Deadlock in DBMS
    • Log Based Recovery
  • NoSQL & Types of Databases
    • SQL V/S NoSQL
    • Types of Databases
  • DB Optimization
    • File Organization
      • Hash File Organizations
      • B+ Tree File Organization: A Guide to Efficient Data Indexing
      • Cluster File Organization
    • Indexing in DBMS
      • Primary Indexing
      • Clustered Indexing
      • Secondary Indexing
      • Multilevel Indexing
  • Distributed Databases
    • Database Clustering
    • Partitioning and Sharding
    • CAP Theorm
Powered by GitBook
On this page
  • Creating New DataBase
  • Populating Data

Was this helpful?

  1. SQL - Structured Query Language

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

-- Use the "company_db" database
USE company_db;

-- Insert data into the "worker" table
INSERT INTO worker (first_name, last_name, hire_date, department, salary, manager_id)
VALUES
    ('John', 'Doe', '2020-01-15', 'HR', 55000.00, NULL),
    ('Jane', 'Smith', '2019-08-10', 'Finance', 60000.00, 1),
    ('Alice', 'Johnson', '2021-03-22', 'Engineering', 65000.00, 1),
    ('Bob', 'Williams', '2020-05-01', 'Sales', 58000.00, 2);

-- Insert data into the "bonus" table
INSERT INTO bonus (worker_id, bonus_amount, bonus_date)
VALUES
    (1, 2000.00, '2021-12-05'),
    (2, 1500.00, '2022-01-20'),
    (3, 1800.00, '2022-02-15');

-- Insert data into the "title" table
INSERT INTO title (worker_id, job_title, title_start_date)
VALUES
    (1, 'HR Manager', '2020-01-15'),
    (2, 'Financial Analyst', '2019-08-10'),
    (3, 'Software Engineer', '2021-03-22');
    

PreviousType of Commands in SQLNextData Retrieval Commands

Last updated 1 year ago

Was this helpful?

Bonus Table
Title Table
Worker Table