Notes of Class 12th DCC
Notes of Class 12th DCC
Data:
Data is raw, unprocessed facts or figures that, on their own, have little meaning. It represents basic
elements like numbers, text, dates, or even observations.
Information:
Definition: Information is processed or organized data that has been given meaning, context, or
relevance. It provides value and helps in decision-making or understanding.
Introduction to Databases
A database is a structured collection of data that is stored and managed in a way that allows for easy
access, manipulation, and updating. It is designed to handle large amounts of information by
organizing it into tables, records, and fields in a way that is efficient, reliable, and secure.
Databases are a key part of many modern applications, ranging from simple websites to complex
enterprise systems. They help store, retrieve, and manage data, supporting decision-making and
operations within organizations.
Before the use of a computer, a manual file system was used to maintain the records and files. Data
were stored and processed using a traditional file system and it makes it easy to find any information.
In this traditional file system, each file is independent of other file and data in the different file can
be integrated only by writing an individual program for each application.
A Database Management System (DBMS) is a software tool that helps you store, manage, and
retrieve data from a database. It acts as an intermediary between users (or applications) and the
database, making it easier to organize, access, and manipulate large amounts of data.
❖ MySQL
❖ PostgreSQL
❖ Oracle
❖ Microsoft SQL Server
Create, modify, and delete database structures (such as tables, indexes, and views).
2
Allows users to define the structure of the database and its components.
Examples:
▪ CREATE TABLE – To create a new table.
▪ ALTER TABLE – To modify an existing table structure.
▪ DROP TABLE – To delete a table from the database.
6. Security: The DBMS also takes care of the security of data, protecting the data from un-
authorised access. In a typical DBMS, we can create user accounts with different access
permissions, using which we can easily secure our data by restricting user access.
7. Transactions: DBMS supports transactions, which allows us to better handle and man- age
data integrity in real world applications where multi-threading is extensively used.
Difference b/w File System and DBMS
4
✓ Data Security: A Database Management System (DBMS) provides a better platform for data
privacy and security policies thus, helping companies to improve Data Security.
✓ Data integration: Due to the Database Management System we have access to well-
managed and synchronized forms of data thus it makes data handling very easy and gives an
integrated view of how a particular organization is working and also helps to keep track of
how one segment of the company affects another segment.
✓ Data abstraction: The major purpose of a database system is to provide users with an
abstract view of the data
✓ Reduction in data Redundancy: When working with a structured database, DBMS provides
the feature to prevent the input of duplicate items in the database. for e.g. – If there are two
same students in different rows, then one of the duplicate data will be deleted.
✓ Data sharing: A DBMS provides a platform for sharing data across multiple applications and
users, which can increase productivity and collaboration.
✓ Data consistency and accuracy: DBMS ensures that data is consistent and accurate by
enforcing data integrity constraints and preventing data duplication.
✓ Data organization: A DBMS provides a systematic approach to organizing data in a structured
way, which makes it easier to retrieve and manage data efficiently.
✓ Efficient data access and retrieval: DBMS allows for efficient data access and retrieval by
providing indexing and query optimization techniques that speed up data retrieval.
✓ Concurrency and maintained Atomicity: That means, if some operation is performed on one
particular table of the database, then the change must be reflected for the entire database.
✓ Scalability and flexibility: DBMS is highly scalable and can easily accommodate changes in
data volumes and user requirements. DBMS can easily handle large volumes of data, and can
scale up or down depending on the needs of the organization. It provides flexibility in data
storage, retrieval, and manipulation, allowing users to easily modify the structure and
content of the database as needed.
SQL (Structured Query Language) is a standard programming language used for managing and
manipulating relational databases. It allows users to interact with databases by performing various
tasks such as:
5
• Querying Data: SQL enables users to retrieve specific data from a database using the SELECT
statement.
• Inserting Data: Data can be added into a database using the INSERT INTO statement.
• Updating Data: The UPDATE statement is used to modify existing data in the database.
• Deleting Data: SQL allows for deleting records from the database with the DELETE
statement.
• Creating and Modifying Structures: SQL provides commands like CREATE TABLE, ALTER
TABLE, and DROP TABLE to define and manage the structure of a database.
• Managing Permissions: It includes commands like GRANT and REVOKE to control access to
data.
• Joining Tables: SQL allows combining data from multiple tables using JOIN operations.
SQL (Structured Query Language) is a powerful language used for managing and manipulating
relational databases. Here are the key characteristics of SQL:
1. Declarative Language:
SQL is a declarative language, which means users describe what they want to do with data
(e.g., select, insert, update), but not how the database should perform the operations.
2. Platform Independent:
SQL can be used across various platforms and DBMSs (like MySQL, PostgreSQL, SQL Server,
and Oracle).
✓ TRUNCATE: To remove all records from a table, while preserving the structure.
5. Integrity Constraints:
SQL allows the definition of rules to ensure data accuracy and consistency, such as:
✓ NOT NULL: Ensures that a column does not accept NULL values.
6. Normalization:
SQL supports data normalization techniques, which help in organizing data into tables to
minimize redundancy and dependency.
7. Join Operations:
SQL enables combining data from multiple tables using JOIN operations:
✓ LEFT JOIN: Returns all rows from the left table and matching rows from the right.
✓ RIGHT JOIN: Returns all rows from the right table and matching rows from the left.
✓ FULL OUTER JOIN: Returns all rows when there is a match in either left or right table.
8. Aggregation:
SQL supports aggregate functions to summarize data, such as:
Applications of SQL
• Business Intelligence (BI): SQL is extensively used in BI tools and applications to query and
retrieve data from databases for reporting, dashboards, and data analysis. For example, SQL
is used in tools like Tableau, Power BI, and Google Data Studio.
• Data Analytics: Analysts use SQL to extract, manipulate, and aggregate data to uncover
insights and trends, performing complex queries for data mining, statistical analysis, and
predictive modeling.
2. Data Management
• Data Insertion and Updates: SQL is used to insert new records into a database, modify
existing records, and delete outdated or incorrect data. For example, e-commerce platforms
use SQL for managing customer orders, inventories, and product data.
7
• Data Maintenance: Database administrators (DBAs) use SQL to maintain and optimize the
performance of databases, including tasks like database backups, indexing, and schema
modifications.
• Business Operations Management: SQL plays a crucial role in managing large enterprise
systems such as ERP software (e.g., SAP, Oracle ERP). These systems store, retrieve, and
update data related to accounting, supply chain management, inventory, sales, human
resources, and more.
• Customer Data Management: SQL is used in CRM systems (e.g., Salesforce, HubSpot) to
store and manage customer information, sales leads, communications, and transaction
history. Queries help in tracking customer interactions and providing insights into sales
trends.
• Data Security and Audit Logs: SQL helps to manage and audit transaction logs, ensuring
compliance with regulatory standards (e.g., SOX, GDPR).
7. Healthcare Systems
• Electronic Health Records (EHR): SQL is used in healthcare databases to store and retrieve
patient records, medical histories, appointment schedules, lab results, and insurance
information.
• Data Integration: SQL queries can integrate data from various healthcare sources to provide
a comprehensive view of patient care and clinical performance.
8. E-commerce Platforms
• Order Processing: SQL queries track customer orders, process payments, and update order
statuses in real-time.
• User Data Management: Social media platforms (e.g., Facebook, Twitter) use SQL to store
and manage user profiles, posts, comments, and interaction histories. SQL queries help
retrieve data related to user activity and interactions.
• Content Moderation: SQL can be used to track and store flagged content, moderation logs,
and user behavior, ensuring compliance with platform policies.
8
• Student Records: SQL is used to store and manage student information, including grades,
courses, schedules, and attendance.
• Course Management: Educational institutions use SQL for managing course catalogs,
instructor assignments, student enrollments, and assessment data.
• Public Records Management: Government agencies use SQL databases to store and manage
public records, such as tax information, legal documents, and public health records.
• Census and Survey Data: SQL is used to store and analyze data collected through national
15. Research and Scientific Databases
• Bioinformatics: In fields like genomics and bioinformatics, SQL is used to store large datasets
and perform complex queries related to genes, proteins, and sequences.
• Local Data Storage: SQL is used for local data storage in mobile applications, where
lightweight relational databases like SQLite are used to store data on the device, such as user
preferences, offline content, and app settings.
Advantages of SQL
Disadvantages of SQL
Name Description
EXP Returns the e constant (2.71828…) that raises to a power of a specified number
Name Description
Date functions in SQL are used to perform operations on date and time data types, such as retrieving
parts of a date, manipulating date values, calculating date differences, and formatting dates. These
functions are essential for handling time-based data in databases.
an aggregate function is a function that operates on a set of values to return a single value.
CREATE TABLE:
The CREATE TABLE statement in SQL is used to create a new table in a database. The basic syntax
defines the table name, followed by a list of columns and their data types.
11
ALTER TABLE:
The ALTER TABLE statement in SQL is used to modify an existing table's structure. You can use it to
add, modify, or delete columns, constraints, or other table properties.
DROP TABLE:
The DROP TABLE statement in SQL is used to delete an existing table from the database, along with
all the data stored within it. This operation is irreversible, meaning once the table is dropped, both
the table structure and the data are permanently removed.
If you have a table named employees and you want to remove it, you can use the following
statement:
INSERT INTO:
The INSERT INTO statement in SQL is used to add new rows of data into an existing table. This
statement allows you to insert single or multiple rows into a table.
DELETE STATEMENT:
The DELETE statement in SQL is used to remove one or more rows from an existing table. This
operation permanently removes the data from the table, but the structure of the table (such as
columns, constraints, etc.) remains intact.
If you want to delete specific rows based on a condition, use the WHERE clause.
Example:
If you want to delete all rows from a table but keep the table structure (columns, constraints, etc.)
intact, omit the WHERE clause.
Example:
You can specify multiple conditions in the WHERE clause to delete rows that meet more complex
criteria.
Example:
UPDATE STATEMENT:
The UPDATE statement in SQL is used to modify the existing data in one or more rows of a table. It
allows you to change the values in one or more columns for specific rows based on a given condition.
You can update specific rows by using the WHERE clause to filter the rows based on a condition.
13
Example:
Suppose you have a table employees with columns employee_id, first_name, last_name, and salary.
If you want to update the salary of the employee with employee_id = 1, you would write:
UPDATE employees
SET salary = 60000
WHERE employee_id = 1;
You can update multiple columns in the same row by separating each column-value pair with a
comma.
Example:
If you want to update both the salary and the last_name for the employee with employee_id = 2, you
would write:
UPDATE employees
SET salary = 65000, last_name = 'Smith'
WHERE employee_id = 2;
If you omit the WHERE clause, all rows in the table will be updated. Be cautious, as this will affect
every row in the table.
Example:
UPDATE employees
SET salary = 50000;
SELECT STATEMENT:
The SELECT statement in SQL is used to query data from one or more tables in a database. It allows
you to retrieve specific columns, rows, or combinations of both based on the conditions you specify.
To select specific columns from a table, list the column names in the SELECT statement.
Example:
Example:
SELECT *
FROM employees;
The DISTINCT keyword is used to eliminate duplicate values in the result set.
Example:
You can use aggregate functions like COUNT(), SUM(), AVG(), MIN(), and MAX() to perform
calculations on your data.
Example (SUM):
SELECT SUM(salary)
FROM employees
WHERE department_id = 3;
You can combine conditions using logical operators like AND, OR, and NOT.
Example:
SQL CLAUSES:
1. WHERE
The WHERE clause is used to filter records based on specified conditions. It is used to retrieve only
those rows that meet the condition(s).
Example:
2. GROUP BY
The GROUP BY clause is used to group rows that have the same values in specified columns into
summary rows, like calculating the average salary or total sales per department.
Example:
3. HAVING
The HAVING clause is used to filter groups created by GROUP BY. It is similar to the WHERE clause but
applies to grouped data.
Example:
4. ORDER BY
The ORDER BY clause is used to sort the result set by one or more columns in either ascending (ASC)
or descending (DESC) order.
Example:
JOINS IN SQL:
In SQL, the JOIN operation is used to combine data from two or more tables based on a related
column between them. It helps in retrieving related data from multiple tables, typically by matching
columns that share common values.
✓ Natural Join
✓ Inner Join (Equi Join)
✓ Left Outer Join
✓ Right Outer Join
✓ Full Outer Join
NATURAL JOIN:
A NATURAL JOIN is a type of join that automatically joins two tables based on all columns with the
same name and data type in both tables. It simplifies the SQL query by eliminating the need to
16
explicitly specify the join condition using the ON keyword. Instead, the database system
automatically matches columns with the same name and performs the join.
Example Query:
An INNER JOIN returns only the rows that have matching values in both tables. If there is no match,
the row is excluded from the result.
Example:
Result: Returns a list of employees and their respective departments, but only where a match exists
for the department_id in both tables.
A LEFT JOIN (or LEFT OUTER JOIN) returns all the rows from the left table and the matched rows from
the right table. If there is no match, NULL values are returned for columns of the right table.
Example:
To list all employees along with their department names (including employees without a
department):
Result: Returns all employees, including those without a department. For employees without a
department, the department_name will be NULL.
A RIGHT JOIN (or RIGHT OUTER JOIN) returns all the rows from the right table and the matched rows
from the left table. If there is no match, NULL values are returned for columns of the left table.
17
Example:
To list all departments along with the employees who belong to those departments (including
departments without employees):
Result: Returns all departments, including those without employees. For departments without
employees, the first_name and last_name will be NULL.
A FULL JOIN (or FULL OUTER JOIN) returns all rows when there is a match in either the left or the
right table. If there is no match, NULL values are returned for the non-matching side.
Example:
To list all employees and all departments, including those without a department or without
employees:
Result: Returns all employees and all departments. For employees without a department, the
department_name will be NULL. For departments without employees, the first_name and last_name
will be NULL.
Join
Description Result
Type
Returns all rows from the left table All rows from the left table, matched rows from the
LEFT
and matched rows from the right right table. If no match, NULL is returned for columns
JOIN
table. from the right table.
Returns all rows from the right table All rows from the right table, matched rows from the
RIGHT
and matched rows from the left left table. If no match, NULL is returned for columns
JOIN
table. from the left table.
FULL Returns rows when there is a match All rows from both tables, with NULL values for columns
JOIN in either table. of the table that has no matching rows.