SQL Tutorial: Employee Management Project šŸŽÆ

beginner
9 min

SQL Tutorial: Employee Management Project šŸŽÆ

Welcome to the SQL Tutorial! Today, we're going to create a simple Employee Management system using SQL. This project is designed for beginners and intermediates, so let's get started! šŸ“

What is SQL?

SQL (Structured Query Language) is a programming language used to manage and manipulate databases. It allows us to create, read, update, and delete records in a database. šŸ’” Pro Tip: SQL is a must-know skill for any developer!

Setting Up Our Employee Management Database

Let's create a new database called employee_db. We'll also create a table called employees to store our employee data.

sql
CREATE DATABASE employee_db; USE employee_db; CREATE TABLE employees ( id INT PRIMARY KEY, first_name VARCHAR(100), last_name VARCHAR(100), email VARCHAR(255), department VARCHAR(50), salary DECIMAL(10, 2) );

šŸ“ Note: We've created a table with fields for id, first_name, last_name, email, department, and salary. The id field is our primary key, which uniquely identifies each employee.

Inserting Data into Our Employees Table

Now that we have our table set up, let's insert some data into it.

sql
INSERT INTO employees (id, first_name, last_name, email, department, salary) VALUES (1, 'John', 'Doe', 'john.doe@example.com', 'IT', 60000); INSERT INTO employees (id, first_name, last_name, email, department, salary) VALUES (2, 'Jane', 'Smith', 'jane.smith@example.com', 'HR', 55000);

šŸ“ Note: We've inserted two employees with their respective details.

Querying Our Employee Data

Now that we have data in our database, let's learn how to query it.

sql
SELECT * FROM employees;

This query will return all the data from the employees table.

Filtering and Sorting Our Data

We can also filter and sort our data based on specific conditions.

sql
SELECT * FROM employees WHERE department = 'IT'; SELECT * FROM employees ORDER BY salary DESC;

šŸ“ Note: The first query will return only the IT department employees, and the second query will return all employees sorted by salary in descending order.

Updating and Deleting Data

We can also update and delete data in our database.

sql
UPDATE employees SET salary = 65000 WHERE id = 1; DELETE FROM employees WHERE id = 2;

šŸ“ Note: The first query will increase John's salary to 65000, and the second query will delete Jane's record from the employees table.

Quiz Time!

Quick Quiz
Question 1 of 1

What does SQL stand for?

Quick Quiz
Question 1 of 1

What does the `id` field in our `employees` table represent?

That's it for today! We've learned how to create a database and table, insert data, query data, filter and sort data, and update and delete data. Keep practicing, and you'll become a SQL pro in no time! šŸš€

Stay tuned for more tutorials on CodeYourCraft!