Skip to content

Latest commit

 

History

29 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

HR database management system | MySQL, SQL

1. Database

A Database is an organized collection of data stored electronically.

Example table:

Student_ID     Name         Department

 101            Suganya       CSE 
 
 102            Divya         IT

2 DBMS (Database Management System)

A DBMS is software that allows users to create, store, update, delete, and retrieve data from a database.

Features: Create databases Insert records Update records Delete records Search data Manage users Examples: FoxPro dBase Microsoft Access

3. RDBMS (Relational Database Management System)

An RDBMS is an advanced type of DBMS where data is stored in tables, and relationships are established using Primary Keys and Foreign Keys.

Example:

Department Table:

Dept_ID    Department 

 1          CSE 
 
 2          IT

4. SQL (Structured Query Language)

SQL is a standard language used to create, manage, and manipulate data in relational databases.

Uses of SQL: - Create databases and tables - Insert data - Retrieve data - Update data - Delete data - Manage users and permissions - Create views, indexes, and stored procedures

5. MYSQL

MySQL is an open-source RDBMS developed by Oracle Corporation that stores data in tables and uses SQL to perform database operations.

Features of MySQL

-Open source
-Fast and reliable
-Supports multiple users
-Stores data in tables

CREATE DATABASE

Screenshot 2026-08-04 192628

CREATE TABLE

Definition

A table is a database object that stores related information in the form of rows (records) and columns (fields).

Structure of a Table

Column (Field): Defines the type of information stored (e.g., employee_id, name, salary).

Row (Record): Represents one complete set of data.

CREATE EMPLOYEE1 TABLE

image

CREATE ATTENDANCE1 TABLE

image

CREATE PAYROLL1 TABLE

image

CREATE LEAVE_REQUESTS1 TABLE

image

INSERT

Definition:

The INSERT command is used to add one or more new records into a database table. It allows users to store new information in the database.

INSERT DATAS INTO EMPLOYEE1 TABLE

image

INSERT DATAS INTO ATTENDANCE1 TABLE

image

INSERT DATAS INTO PAYROLL1 TABLE

image

INSERT DATAS INTO LEAVE_REQUESTS1 TABLE

image

SELECT

Definition:

The SELECT command is the most commonly used SQL command. It retrieves data from one or more tables and can be combined with clauses such as WHERE, ORDER BY, GROUP BY, and HAVING to produce meaningful results.

RETRIVE EMPLOYEE1 TABLE

image

RETRIVE ATTENDANCE1 TABLE

image

RETRIVE PAYROLL1 TABLE

image

RETRIVE LEAVE_requests1 TABLE

image

FROM Clause

Definition:

The FROM clause is used to specify the table from which the data will be retrieved. It tells the SQL query where to fetch the records.

example Screenshot 2026-08-04 201110

WHERE Clause

Definition:

The WHERE clause is used to filter records based on a specified condition. It returns only those rows that satisfy the given condition.
image

ORDER BY Clause

Definition

The ORDER BY clause is used to sort the result set in either ascending (ASC) or descending (DESC) order based on one or more columns.
image

GROUP BY Clause

Definition:

The GROUP BY clause is used to group rows that have the same values in a specified column into summary rows. It is commonly used with aggregate functions such as COUNT(), SUM(), AVG(), MIN(), and MAX().
image

AGGRIGATE FUNCTIONS

1. COUNT()

Definition:

The COUNT() function is used to count the total number of rows or non-NULL values in a column.
image

2. SUM()

Definition:

The SUM() function is used to calculate the total sum of numeric values in a specified column.

image

3. AVG()

Definition:

The AVG() function is used to calculate the average value of a numeric column.
image

4. MAX()

Definition:

The MAX() function is used to return the highest value from a specified column.
image

5. MIN()

Definition:

The MIN() function is used to return the lowest value from a specified column.
image

HAVING Clause

Definition:

The HAVING clause is used to filter grouped records after the GROUP BY clause has been applied. It is mainly used with aggregate functions.
image

LIMIT Clause

Definition:

The LIMIT clause is used to restrict the number of rows returned by a query. It is useful when you want to display only a specific number of records.
image

DISTINCT

Definition

DISTINCT is a SQL keyword used to remove duplicate values from the result set and return only unique (different) records from one or more columns.

It is commonly used when a table contains repeated values and you want to display each value only once.
image

ARITHMETIC OPERATORS:

Definition:

Arithmetic operators are used to perform mathematical calculations on numeric values in SQL.
+ (Addition):
 Adds two numeric values.
image

Subtraction (-)

Subtracts one numeric value from another.
image

* (MULTIPLICATION)

Multiplies two numeric values.
image

/ (DIVITION)

Divides one numeric value by another.
image

COMPARITION OPERATORS

Definition:

Comparison operators are used to compare two values. They return TRUE if the condition is satisfied; otherwise, they return FALSE.

= (equal to)

 Checks if two values are equal.
image

!= or <> (not equal to)

Checks if two values are not equal.
image

> (greater then)

   Checks if the left value is greater than the right value.
image

< (lesser then)

Checks if the left value is less than the right value.
image

>= (greater then or equal to)

   	Checks if the left value is greater than or equal to the right value.
image

<= (lesser then or equal to)

Checks if the left value is less than or equal to the right value.
image

LOGICAL OPEARATOR

Definition:

Logical operators are used to combine multiple conditions in a SQL query.

AND

Returns TRUE only if all conditions are TRUE.
image

OR

Returns TRUE if at least one condition is TRUE.
image

NOT

Reverses the result of a condition (TRUE becomes FALSE and FALSE becomes TRUE).
image

SPECIAL OPEARATORS

Definition:

Special operators are used to perform special types of comparisons and filtering in SQL queries.

BETWEEN

Selects values within a specified range (inclusive).
image

IN

Checks whether a value matches any value in a given list.
image

NOT IN

Checks whether a value does not match any value in a given list.
image

LIKE

 Searches for a specified pattern in a column.
image

IS NULL

Checks whether a column contains NULL values.
image

IS NOT NULL

Checks whether a column contains non-NULL values.
image

STRING FUNCTIONS

Definition:

String functions are built-in SQL functions used to manipulate and process text (character) data.

CONCAT()

Combines two or more strings into a single string.
image

UPPER()

Converts all characters in a string to uppercase.
image

LOWER()

Converts all characters in a string to lowercase.
image

LENGTH()

Returns the number of bytes in a string.
image

CHAR_LENGTH()

Returns the number of characters in a string.
image

SUBSTRING()

Extracts a specified part of a string.
image

LEFT()

Returns the leftmost specified number of characters from a string.
image

RIGHT()

Returns the rightmost specified number of characters from a string.
image

REPLACE()

Replaces all occurrences of a specified substring with another substring.
image

TRIM()

Removes leading and trailing spaces from a string.
image

REVERSE()

Reverses the characters in a string.
image

ALTER

definition:

MySQL ALTER statement is used when you want to change the name of your table or any table field.

It is also used to add or delete an existing column in a table.

The ALTER statement is always used with "ADD", "DROP" and "MODIFY" commands according to the situation.
image

Add a new column

image

Modify a column datatype

image

Change column name and datatype

image

Rename a column

image

UPDATE

Definition:

The UPDATE command is used to modify the existing records in a table. It can update one or multiple rows based on a specified condition.
image

DELETE

Definition:

The DELETE command is used to remove one or more records from a table. It supports conditions to delete only the required records while keeping the table structure unchanged.
image

TRUNCATE

Definition:

The TRUNCATE command is used to remove all records from a table while preserving the table structure, columns, indexes, and constraints. It is faster than the DELETE command because it removes all rows at once.
image

DROP

Definition:

The DROP command is used to permanently remove a database object, such as a table or database, along with all its data, structure, indexes, and constraints. Once dropped, the object cannot be used unless it is created again.
image

INNER JOIN

Definition:

INNER JOIN is used to retrieve only the records that have matching values in both tables. If there is no matching record in either table, it is not included in the result.

Key Point: Returns only matching rows from both tables.

image

LEFT JOIN (LEFT OUTER JOIN)

Definition:

LEFT JOIN is used to retrieve all records from the left table and the matching records from the right table. If there is no matching record in the right table, the result displays NULL values for the right table's columns.

Key Point: Returns all rows from the left table and only the matching rows from the right table.

image

RIGHT JOIN (RIGHT OUTER JOIN)

Definition:

RIGHT JOIN is used to retrieve all records from the right table and the matching records from the left table. If there is no matching record in the left table, the result displays NULL values for the left table's columns.

Key Point: Returns all rows from the right table and only the matching rows from the left table.

image

SUB QUERY

Definition:

A subquery is a query written inside another SQL query. It is used to obtain a result that is then used by the outer query
.

Employees whose CTC is greater than average CTC

image

Employees who have attendance status Absent

image

CTE (COMMON TABLE EPRESSION)

Definition:

CTE (Common Table Expression) is a temporary named result set created using the WITH keyword. It makes complex queries easier to read and reuse.

Calculate net salary using CTE

image

CTE with attendance

image

WINDOW FUNCTIONS

Definition:

A window function performs calculations across a set of related rows without combining those rows into a single row.

Unlike GROUP BY, a window function keeps the individual rows.

** Common window functions:**

ROW_NUMBER()
RANK()
DENSE_RANK()
SUM()
AVG()
MIN()
MAX()
LAG()
LEAD()

ROW_NUMBER()

Definition:

ROW_NUMBER() assigns a unique sequential number to each row based on the specified ordering.

Rank employees according to CTC:

image

RANK()

Definition:

RANK() assigns a rank to each row based on the specified ordering. If two rows have the same value, they receive the same rank, and the next rank is skipped.
image

DENSE_RANK()

Definition:

DENSE_RANK() assigns the same rank to equal values, but unlike RANK(), it does not skip the next rank.
image

PARTITION BY

Definition:

PARTITION BY divides the rows into groups before applying a window function.
image

LEAD()

Definition:

LEAD() retrieves the value from the next row in the specified order.
image

LAG()

Definition:

LAG() retrieves the value from the previous row in the specified order.
image

VIEW

definition:

 A VIEW in SQL is like a virtual table. It doesn’t store data itself but shows the result of a query as if it were a table. You can query a view just like a normal table.
image image

stored procedures

A Stored Procedure in SQL is a precompiled collection of one or more SQL statements stored in the database, which can be executed as a single unit. It improves performance, supports parameters, enhances security, and allows reuse of complex logic.
image image

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors