> For the complete documentation index, see [llms.txt](https://codexpress.gitbook.io/welcome-to-datagenesis/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codexpress.gitbook.io/welcome-to-datagenesis/sql-structured-query-language/working-with-commands.md).

# Working With Commands

### Creating New DataBase

```sql
-- 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)
);

```

<figure><img src="https://3050504885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF5kDastEMl3X0KvcyG2z%2Fuploads%2FBKPf0yWF0pQygO9EYFgm%2Fimage.png?alt=media&amp;token=80c50416-c5de-433c-86b7-3f20295cbfd3" alt=""><figcaption></figcaption></figure>

### Populating Data

```sql
-- 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');
    

```

<figure><img src="https://3050504885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF5kDastEMl3X0KvcyG2z%2Fuploads%2FkTh2AUv4S74shZSTCOzN%2Fimage.png?alt=media&amp;token=8793c8e6-2c76-40fb-8872-f19789480f20" alt=""><figcaption><p>Bonus Table</p></figcaption></figure>

<figure><img src="https://3050504885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF5kDastEMl3X0KvcyG2z%2Fuploads%2Fs57xX5yuBE0P1B352dcM%2Fimage.png?alt=media&amp;token=c9970282-edb7-458e-a8e6-3d9190ab26c0" alt=""><figcaption><p>Title Table</p></figcaption></figure>

<figure><img src="https://3050504885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF5kDastEMl3X0KvcyG2z%2Fuploads%2Fbc67Ge1EaVTnEWrf6ozK%2Fimage.png?alt=media&amp;token=b97af9c4-d59a-4ea2-8b12-a0c01c9c01c3" alt=""><figcaption><p>Worker Table</p></figcaption></figure>
