Lecture 2.1 A
Lecture 2.1 A
DEPARTMENT: USB
MCA
Business Analytics
23CAH-701
2
A database is a structured collection of data organized and
stored in a way that allows for efficient retrieval, manipulation,
and management of information. It is designed to provide a
systematic approach to storing, managing, and retrieving data.
Databases are used to store and manage large amounts of data
for various applications, ranging from small personal projects to
enterprise-level systems. They are widely used in areas such as
business, finance, healthcare, education, e-commerce, and many
others.
The main purpose of a database is to provide a central repository
where data can be stored securely and accessed by multiple
users or applications concurrently. It offers a structured format
for organizing data, enabling efficient storage, retrieval, and
modification operations. Databases also support data integrity
and enforce rules and constraints to maintain the accuracy and
consistency of the stored data.
3
Database Components
1.Data: It represents the information stored in the
database, organized in tables or other data structures
based on the chosen database model.
2.Database Management System (DBMS): It is a software
system responsible for managing the database. The
DBMS provides tools and functions for creating,
modifying, and querying the database. It also handles
tasks such as data security, concurrency control, and
backup and recovery.
3.Database Schema: It defines the structure of the
database, including tables, fields, relationships, and
constraints. The schema acts as a blueprint for
organizing and representing data. 4
4. Queries: Queries are used to retrieve specific information from
the database. They allow users or applications to search, filter, and
sort data based on various criteria.
There are different types of database models, each with its own
strengths and use cases. Some popular database models include
the relational model, where data is organized in tables with rows
and columns, and the NoSQL (Not Only SQL) model, which provides
flexible data structures suitable for handling unstructured or semi-
structured data.
5
INTRODUCTION TO DBMS
20
SQL Distinct keyword
• SQL DISTINCT clause is used to remove the duplicates columns from
the result set.
• SELECT DISTINCT returns only distinct (different) values.
• DISTINCT eliminates duplicate records from the table.
• DISTINCT can be used with aggregates: COUNT, AVG, MAX, etc.
• Syntax:
SELECT DISTINCT expressions FROM tables [WHERE conditions];
21
SELECT DISTINCT SALARY FROM EMPLOYEES ORDER BY SALARY;
22
SQL IN Operator
• The SQL IN is a logical operator that allows us to specify multiple
values or sub query in the WHERE clause.
• It returns all rows in which the specified column matches one of the
values in the list. The list of values or sub query must be specified in
the parenthesis e.g. IN (select query) or IN (Value1, Value2, Value3,
…).
• Syntax:
SELECT Column_Name_1, Column_Name_2, ......, Column_Name_N F
ROM Table_Name WHERE Column_Name IN (Value_1, Value_2, .......,
Value_N);
23
EmpId FirstName LastName Email Salary DeptId
1 'John' 'King' 'john.king@ab 33000 1
c.com'
2 'James' 'Bond' 1
3 'Neena' 'Kochhar' '[email protected] 17000 2
om'
4 'Lex' 'De Haan' '[email protected] 15000 1
'
5 'Amit' 'Patel' 18000 3
6 'Abdul' 'Kalam' '[email protected] 25000 4
om'
SELECT EmpId, FirstName, LastName, Salary FROM Employee WHERE EmpId IN (1, 3, 5, 6)
24
SQL Wildcard Characters
• A wildcard character is used to substitute one or more characters in a
string.
• Wildcard characters are used with the LIKE operator. The LIKE
operator is used in a WHERE clause to search for a specified pattern in
a column.
Symbol Description
% Represents zero or more
characters
_ Represents a single character
25
The % wildcard represents any number of characters, even zero
characters.
• Return all customers that starts with the letter 'a’:
Example:- SELECT * FROM Customers WHERE CustomerName LIKE 'a%’;
• Return all customers that ends with the pattern 'es’:
Example:- SELECT * FROM Customers WHERE CustomerName LIKE '%es’;
The _ wildcard represents a single character.
• Return all customers with a City starting with any character, followed
by "ondon":
Example:- SELECT * FROM Customers WHERE City LIKE '_ondon';
26
THANK YOU
For queries
Email:
[email protected]