0% found this document useful (0 votes)
16 views12 pages

BDST 122 RDBMS

The document covers the foundations of SQL and advanced database design, emphasizing the importance of efficient data management, integrity, and performance. It details querying techniques, including SELECT statements and JOIN operations, as well as data modification commands like INSERT, UPDATE, and DELETE. Additionally, it introduces normalization and denormalization processes, along with advanced SQL data types for handling date and time data.

Uploaded by

ompmore1221
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views12 pages

BDST 122 RDBMS

The document covers the foundations of SQL and advanced database design, emphasizing the importance of efficient data management, integrity, and performance. It details querying techniques, including SELECT statements and JOIN operations, as well as data modification commands like INSERT, UPDATE, and DELETE. Additionally, it introduces normalization and denormalization processes, along with advanced SQL data types for handling date and time data.

Uploaded by

ompmore1221
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

BDST 122: Relational Database Management System

UNIT : 1
Foundations of SQL and database design

 Introduction to advanced database design


Advanced database design of sophisticated techniques and
methodologies aimed at creating databases that are efficient, scalable, and
capable of handling complex data structures and relationships.
As organizations grow and data management needs advanced database
design concepts become crucial for maintaining performance, ensuring data
integrity, and supporting diverse application requirements.
Its techniques and methodologies to handle large-scale, distributed, or
specialized data requirements.

 Understanding the importance of advanced database design

Advanced database design is critical for organizations seeking to manage


complex data efficiently, ensure data integrity, and support business
operations at scale. As data becomes increasingly central to decision-making
and operations.
1. Enhanced Performance and Efficiency
 Optimized Queries: Advanced design techniques like indexing and query
optimization reduce query response times, ensuring that data retrieval is fast
and efficient.
 Efficient Data Storage: Proper normalization reduces data redundancy,
leading to more efficient use of storage and quicker data access.

2. Support for Advanced Analytics


 Data Warehousing: Advanced design facilitates the creation of data
warehouses that support complex analytical queries, enabling businesses to
derive insights and make informed decisions.
 Real-Time Analytics: Designing databases for real-time data processing
allows organizations to act on data as it is generated, providing a competitive
edge.
 Key principle of good database design

A well-designed database is crucial for ensuring efficient data management,


high performance, and ease of maintenance.

1. Data Integrity
 Accuracy and Consistency: Ensure that data is accurate, consistent, and
reliable. Implement integrity constraints such as primary keys, foreign keys,
and unique constraints to maintain relationships and prevent data anomalies.
 Validation Rules: Use validation rules to enforce correct data entry,
minimizing errors and inconsistencies.

2. Security
 Access Control: Implement robust access control mechanisms to ensure that
only authorized users have access to specific data. Use role-based access
control (RBAC) and ensure proper user authentication.

 Querying data with SELECT

It allows users to retrieve specific data by specifying the columns to be


displayed, applying conditions, sorting results, and even aggregating data.

1. Basic Syntax

SELECT column1, column2, ...


FROM table_name;

2. Selecting All Columns

SELECT * FROM table_name;

3. Filtering Rows with WHERE

SELECT column1, column2


FROM table_name
WHERE condition;

4. Sorting Results with ORDER BY

SELECT column1, column2


FROM table_name
ORDER BY column1 ASC|DESC;
 Join
Joins in SQL are used to combine rows from two or more tables based
on a related column between them. They are essential for retrieving data from
multiple tables in a relational database.

Here’s a summary of the JOIN operations we applied:


1. INNER JOIN: Only matching rows from both tables.
2. LEFT JOIN: All rows from the left table, and matching rows from the right
table.
3. RIGHT JOIN: All rows from the right table, and matching rows from the left
table.
4. FULL OUTER JOIN: All rows when there’s a match in either table, with
NULL for non-matching rows.
5. CROSS JOIN: Cartesian product of both tables, returning all combinations of
rows.
The CROSS JOIN returns the Cartesian product of both tables, i.e., every row in the left table
is combined with every row in the right table.

Two Tables:

 employees – This will contain information about employees.


 departments – This will contain information about departments.

CREATE TABLE employees (


employee_id INT PRIMARY KEY,
name VARCHAR(50),
department_id INT
);
INSERT INTO employees (employee_id, name, department_id)
VALUES
(1, 'Alice', 101),
(2, 'Bob', 102),
(3, 'Charlie', 103),
(4, 'David', NULL);

CREATE TABLE departments (


department_id INT PRIMARY KEY,
department_name VARCHAR(50)
);

INSERT INTO departments (department_id, department_name)


VALUES
(101, 'HR'),
(102, 'IT'),
(103, 'Marketing'),
(104, 'Finance');

1. INNER JOIN

SELECT employees.name, departments.department_name

FROM employees

INNER JOIN departments

ON employees.department_id = departments.department_id;

Result:

name department_name

Alice HR

Bob IT

Charlie Marketing

2. LEFT JOIN (or LEFT OUTER JOIN)

SELECT employees.name, departments.department_name

FROM employees

LEFT JOIN departments

ON employees.department_id = departments.department_id;

Result:

name department_name

Alice HR

Bob IT

Charlie Marketing

David NULL
3. RIGHT JOIN (or RIGHT OUTER JOIN)

SELECT employees.name, departments.department_name

FROM employees

RIGHT JOIN departments

ON employees.department_id = departments.department_id;

Result:

name department_name

Alice HR

Bob IT

Charlie Marketing

NULL Finance

4. FULL OUTER JOIN

SELECT employees.name, departments.department_name

FROM employees

FULL OUTER JOIN departments

ON employees.department_id = departments.department_id;

Result:

name department_name

Alice HR

Bob IT

Charlie Marketing

David NULL

NULL Finance

 WHERE : - - -
The WHERE clause is used to filter records.
It is used to extract only those records that full fill a specified condition.
SELECT column1, column2, ...
FROM table_name
WHERE condition;

Example :----
SELECT * FROM marks
WHERE student_id = 1;

SELECT * FROM marks


WHERE subject = 'Math';

SELECT * FROM marks


WHERE score > 80;

SELECT * FROM marks


WHERE subject IN ('Math', 'Science');

SELECT * FROM marks


WHERE score BETWEEN 80 AND 90;

SELECT * FROM marks


WHERE subject LIKE '%Eng%';

Data modification with INSERT , UPDATE and DELETE :- - -


1) INSERT INTO Statement : - - -
The INSERT INTO statement is used to insert new records in a table.
INSERT INTO Syntax
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
Example :
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode,
Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

2) UPDATE Statement: - - -
The UPDATE statement is used to modify the existing records in a table.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Example :
UPDATE Customers
SET ContactName = 'Ram', City= 'pune'
WHERE CustomerID = 1;

3) DELETE Statement
The DELETE statement is used to delete existing records in a table.
DELETE Syntax
DELETE FROM table_name WHERE condition;
Example:
DELETE FROM Customers WHERE CustomerName='Ram';
Delete All Records
DELETE FROM table_name;
Example :
DELETE FROM Customers;
Delete a Table
To delete the table completely, use the DROP TABLE statement:
Example : Remove the Customers table:
DROP TABLE Customers;

Introduction to Normalization and Denormalization: - - -


Normalization : - - -
The process of organizing data in a database to reduce redundancy and improve
data integrity. It involves decomposing a database into two or more tables and
defining relationships between them to ensure data dependencies are logical. The key
goals are to eliminate redundant data and ensure data dependencies make sense.

Step 1: First Normal Form (1NF)


 Remove repeating groups.
 Ensure each column contains atomic values.
Denormalization: -
The process of combining normalized tables to improve read performance and
simplify queries. It involves adding redundancy to a database to reduce the number of
joins and improve query performance, often at the cost of increased storage and
potential update anomalies.
 Advanced SQL data types-Data and times data types :
These data types allow for storing, retrieving, and manipulating dates and
times in a standardized format.
DATE
 Description: Stores only date values (year, month, day).
 Format: 'YYYY-MM-DD'
 Example: '2025-01-20'
TIME
 Description: Stores only time values (hour, minute, second).
 Format: 'HH:MM:SS'
 Example: '14:30:00'
DATETIME
 Description: Stores both date and time values.
 Format: 'YYYY-MM-DD HH:MM:SS'
 Example: '2025-01-20 14:30:00'
TIMESTAMP
 Description: Stores a combination of date and time, with the added capability
of tracking changes (automatic initialization and updating).
 Format: 'YYYY-MM-DD HH:MM:SS'
 Example: '2025-01-20 14:30:00'
Functions and Operations with Date and Time Types:
1. CURRENT_DATE: Returns the current date.
o Example: SELECT CURRENT_DATE;
2. CURRENT_TIME: Returns the current time.
o Example: SELECT CURRENT_TIME;
3. CURRENT_TIMESTAMP: Returns the current date and time.
o Example: SELECT CURRENT_TIMESTAMP;
4. DATE_ADD/DATA_SUB: Adds or subtracts a specified time interval to/from
a date.
o Example: SELECT DATE_ADD ('2025-01-20', INTERVAL 10 DAY);
5. DATEDIFF: Calculates the difference between two dates.
o Example: SELECT DATEDIFF ('2025-01-20', '2025-01-10');
6. EXTRACT: Extracts a specific part (year, month, day, etc.) from a date/time.
o Example: SELECT EXTRACT (YEAR FROM '2025-01-20');
Other Example: -----
Creating a Table with Date and Time Types:
CREATE TABLE EventSchedule (
EventID INT PRIMARY KEY,
EventName VARCHAR(100),
EventDate DATE,
StartTime TIME,
EndTime TIME,
CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Inserting Data:
INSERT INTO EventSchedule (EventID, EventName, EventDate, StartTime,
EndTime) VALUES (1, 'Meeting', '2025-02-10', '09:00:00', '10:30:00');
Retrieving Data with Date Filtering:
SELECT EventName, EventDate, StartTime FROM EventSchedule
WHERE EventDate = '2025-02-10';

You might also like