Skip to content

Instantly share code, notes, and snippets.

@marklocklear
Last active January 27, 2025 14:22
Show Gist options
  • Save marklocklear/eb2c965032777ce36536b4e1091ff1e4 to your computer and use it in GitHub Desktop.
Save marklocklear/eb2c965032777ce36536b4e1091ff1e4 to your computer and use it in GitHub Desktop.
Employees, dept and projects database
-- Create employees table
CREATE TABLE employees (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
department_id INT,
salary DECIMAL(10, 2)
);
-- Create departments table
CREATE TABLE departments (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL
);
-- Create projects table
CREATE TABLE projects (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
manager_id INT
);
-- Insert data into departments
INSERT INTO departments (name)
VALUES
('HR'),
('Engineering'),
('Marketing');
-- Insert data into employees
INSERT INTO employees (name, department_id, salary)
VALUES
('Alice', 1, 55000),
('Bob', 2, 70000),
('Charlie', 2, 72000),
('Diana', NULL, 60000); -- No department assigned
-- Insert data into projects
INSERT INTO projects (name, manager_id)
VALUES
('Project A', 1), -- Managed by Alice
('Project B', 2), -- Managed by Bob
('Project C', NULL); -- No manager assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment