0% found this document useful (0 votes)
14 views34 pages

Overview of Database Management Systems

The document provides an overview of Database Management Systems (DBMS), including definitions, purposes, advantages, and disadvantages. It details various SQL commands, their classifications, and specific MySQL features, along with examples of database operations such as creating tables, inserting records, and querying data. Additionally, it explains key terminology related to databases and SQL, including concepts like primary keys, foreign keys, and aggregate functions.

Uploaded by

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

Overview of Database Management Systems

The document provides an overview of Database Management Systems (DBMS), including definitions, purposes, advantages, and disadvantages. It details various SQL commands, their classifications, and specific MySQL features, along with examples of database operations such as creating tables, inserting records, and querying data. Additionally, it explains key terminology related to databases and SQL, including concepts like primary keys, foreign keys, and aggregate functions.

Uploaded by

mishrakushal969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INTRODUCTION

– A Database System is basically a record keeping system.


– Collected form of data is known as database.
– “Database is actually a collection of interrelated data so that it
can be used by various applications.
– Some of the Popular database software are -
• MySQL ( Open Source Software )
• ORACLE Database ( Proprietary Software )
• MS SQL Server
• SQLite (open Source)
• MariaDB
• PostgreSQL (open Source)
PURPOSE/need OF DBMS
– Database Management System (DBMS) is a software whose
purpose is to store databases, maintaining databases and
using databases.
– Its prime purpose is to perform operations on databases and
to provide data when required.
– DBMS reduces Data Redundancy.
– It improves data security.
– It stores data in organized and Integrated form.
– Data remains error free.
– Data is available as and when required.
– Database follows a standard.
ADVANTAGES DISADVANTAGES
Reduce Data Redundancy Complexity
Data Consistency Size
More Information from the Cost of DBMS
same amount of data
Shared Data Additional Hardware Cost
Improved Data Integrity Cost of Conversion
Improved Security Performance
Enforcement of Standards Higher impact of Failure
Economy of scale Data Damage
TERMINOLOGY
Relations: In relational data model, the data is organised into tables(in the
form of rows and columns) called relations.
Domain: A domain is the sets of values from which the actual values appearing
in a given column are drawn.
Tuple : A row (Record) in a relation (Table).
Attribute: A column in a relation (Table).
Degree : It is a number of attributes or columns in a relation (table).
Cardinality : It is a number of tuples or records in a relation.
Primary Key: A column or set of columns that uniquely identifies a row within
a table is called primary key.
Candidate Key: Candidate keys are set of fields (columns with unique values) in
the relation that are eligible to act as a primary key.
Alternate Key: It is a candidate key that is not the primary key.
Foreign Key: A non-key attribute, whose values are derived from the primary
key of some other (Base) table, is known as FOREIGN KEY in its current
table.
DDL: Data Definition/Description Language (DDL). E.g. Create Table, Alter Table
DML: Data Manipulation Language (DML). Insert, Update, Delete.
TCL: Transaction Control Language (TCL). Commit, Rollback, Savepoint
CLASSIFICATION OF SQL COMMANDS
• DDL: Data Definition/Description Language (DDL).
– CREATE TABLE, ALTER TABLE, CREATE VIEW etc
• DML: Data Manipulation Language (DML).
– INSERT INTO, UPDATE, DELETE

• TCL: Transaction Control Language (TCL).


– COMMIT, ROLLBACK, SAVEPOINT

• SESSION CONTROL LANGUAGE.


– ALTER SESSION

• SYSTEM CONTROL LANGUAGE.


– ALTER SYSTEM
MySQL Features
– Fast Speed
– Easy to use.
– Free of cost.
– Support of SQL.
– Portability.
– Various Data types.
– Secure.
– Can handle large data (Scalability and limits).
– Connectivity : uses various protocols to get connected with
clients.
– Localization : server can send error messages to clients in
different laguages.
– Clients and Tools. It provides various client and utility programs.
EMP
EID NAME POST SAL DEPTNO
A101 Ashutosh Manager 20000 20
B202 Naveen Accountant 10000 10
C301 Ravi Clerk 9000 30
D405 Kamal Salesman 8000 20
E505 Anil Salesman 11000 10
F612 Ashish Manager 25000 null
INSERT INTO Emp char
VALUES ( ‘F612’ , ‘Ashish’, ‘Manager’, 25000) ; varchar
• CREATE TABLE • ALTER TABLE :
• INSERT INTO – ADD
• SELECT : – MODIFY
– DISTINCT – DROP
– WHERE clause • CREATE VIEW
• BETWEEN • DROP TABLE
• IN
• LIKE • DROP VIEW
• ORDER BY • JOIN (CS only)
• AGGREGATE FUCNTION
• GROUP BY
• UPDATE
• DELETE
• Open MySQL
• Enter password, if it is having, else press ENTER
PW - apsayo
• CREATE DATABASE (Folder)
MySQL > CREATE DATABASE 12ip2020;
• OPEN DATABASE
MySQL > USE 12ip2020;
• SEE LIST OF DATABASES
– MySQL > SHOW databases;
• SEE STRUCTURE OF TABLE
– MySQL > DESCRIBE Emp;
• SEE LIST OF TABLES
– MySQL > SHOW tables;
• CREATE TABLE
• INSERT RECORDS/TUPLES
CONTSTRAINTS – Table, Col :
Apply security/checks on columns
• PRIMARY KEY – Stopped entering
Duplicate values in col.
• UNIQUE – same as above
• DEFAULT – Allows to store assigned value in
the column, if skipped at the time of entering
record.
• CHECK – restrict entry in given range.
• FOREIGN KEY – for JOIN
• NOT NULL–Not allowed NULL value to be entered.
CREATE TABLE
MySQL > CREATE TABLE Student
( Roll int NOT NULL PRIMARY KEY,
Name varchar(20) NOT NULL,
Class int DEFAULT ‘XII’,
Marks float(5,2) CHECK Marks
between 0 AND 100,
DOB date
);
CHAR vs VARCHAR

• Char(10)
A K A S H

R A V I

• Varchar(10)
A K A S H

R A V I
INSERT INTO
(Entering new RECORD)
MySQL > INSERT INTO Student
VALUES (1, ‘Abhinav’, 11, 89.50) ;
MySQL > INSERT INTO Student
VALUES (2, ‘Abhay’, 12, 99.50) ;
QN. Insert following values in the given table.
7, ‘Kartikeya’,96.5
INSERT INTO Student(Roll,Name,Marks)
VALUES (7, ‘Kartikeya’, 96.5) ;
SELECT (DISPLAY records)
Syntax :
SELECT col_list
FROM table_nm;
Qn.
1. Display all records from table STUDENT.
2. Display entire table.
3. List all records from given table STUDENT.
SELECT Roll, Name, Class, Marks
FROM Student;
• Used to ELAMINATE (Remove) duplicate values
being displayed from the output.
Syntax SELECT DISTINCT col
FROM table_name ;
Qn. Display all classes from table student.
OR
Qn. Display each class from table student.
Ans. SELECT DISTINCT class
FROM Student ;
WHERE clause (FILTER records)
Syntax :
SELECT col_list
FROM table_nm
WHERE Condition ;
Qn.
1. Display records of class 12 from table STUDENT.
SELECT Roll, Name, Class, Marks
FROM Student
WHERE class = 12 ;
SELECT col_list
FROM table_nm
WHERE Condition1 logi. Op. cond.2 ;
• Display records of class 12 from table STUDENT
who are getting marks more than 60.
SELECT *
FROM Student
WHERE class = 12 AND marks > 60 ;
BETWEEN–based on NUMERIC range,
INT, FLOAT, DATE, CHAR
Syntax :
SELECT col_list
FROM table_nm
WHERE Col BETWEEN Lvalue AND Uvalue ;
Qn.
1. Display records of students scoring marks in range 60-90.
2. Display records of students other than above range..
SELECT *
FROM Student
WHERE Marks BETWEEN 60 AND 90 ;
IN – based on list of values in same col
Syntax :
SELECT col_list
FROM table_nm
WHERE Col IN (value1, value2….);
Qn.
1. Display records of class XI and XII.
2. Display records of board classes.
3. Display name of students scoring marks 60,70 & 80.
SELECT *
FROM Student
WHERE class IN ( ‘XI’ , ‘XII’) ;
• Display records of students studying in board
classes scoring marks in range 60-90.
SELECT *
FROM student
WHERE CLASS IN (‘X’, ‘XII’) AND
Marks BETWEEN 60 AND 90 ;
WHERE CLASS IN (‘X’, ‘XII’) AND
Name = ‘Shristi’ ;
WHERE name = ‘Shristi’ and
(CLASS = ‘X’ OR CLASS = ‘XII’ ) ;
LIKE–based on PATTERN matching.
WILD CARD - % (multiple chars),
_ (Single Chars)
Syntax :
SELECT col_list
FROM table_nm
WHERE Col LIKE ‘ % A _ _ %’ ;
Qn.
1. Display records of students whose name start with letter A.
SELECT *
FROM Student
WHERE Name LIKE ‘A %’ ; ‘25/12/2020’
LIKE
Wild Card Character : %, _
SELECT * SELECT *
FROM student FROM student
WHERE Name LIKE ‘A%’ ; WHERE Name LIKE ‘_A%’ ;
SELECT * SELECT *
FROM student FROM student
WHERE Name LIKE ‘%A’ ; WHERE Name LIKE ‘%A_’ ;
SELECT * SELECT *
FROM student FROM student
WHERE Name LIKE ‘%A%’ ; WHERE Name LIKE
‘_ _B _ _ H %’ ;
More question on LIKE command ;
Display records of students whose name –
1. Ends with letter A.
2. Containing letter A.
3. Second letter A.
4. Second last letter A.
5. 3rd letter U and 6th letter V.
6. Having 4 letters name.
Display records of employees having name –
1. First letter as ‘A’.
2. Last letter as ‘A’
3. Second last letter as ‘A’.
4. Containing letter ‘A’.
5. Second and seventh letters are ‘A’ and ‘B’
respectively.
6. Having five digits in salary.
7. Containing vowels
ORDER BY – Arranging records in
Ascending/Descending order in OUTPUT
Syntax :
SELECT col_list FROM table_nm
[ WHERE cond ]
ORDER BY Col ASC/DESC ; (ASC is DEFAULT)
Points to note :
1. Order will be applied on output only not in table.
2. It will be written at last of SELECT command.
3. ASC is a default order, if skipped in query order will be in
ascending
Qn.1. Display records of students in alphabetical order.
SELECT *
FROM Student
ORDER BY Name ASC ;
ORDER BY
1. Display records of students in descending order by
Marks.
2. Display records in DESC order by Marks of class XI.
3. Display records in alphabetical order by name.
4. Display names in descending order by salary.
5. Display name and job in ascending order by salary.
6. Display records of managers in descending order
by DeptNo.
7. Display records of salesman getting salary from
8000 to 12000.
8. Display records in alphabetical order by name and
descending order by salary.
AGGREGATE FUNCTIONS
• SUM() Syntax :
SELECT Agg_Func(Col)
• AVG()
FROM table_name
• MAX()
[Where cond];
• MIN() Points to remember :
1. It will be applied on SINGLE col at a time.
• COUNT() DATE value.
2. It will return SINGLE NUMERIC/ CHAR/

3. Aggregate Function will never be used


• COUNT(*) with WHERE clause.
4. COUNT(col ) without * will not count
NULL value
AGGREGATE FUNCTIONS
1. Display highest salary.
2. Display maximum sal of managers.
3. Display average salary of those employees
getting salary more then 5000.
4. Display minimum salary of clerks from
DeptNo 10.
5. Count strength of employees working in
DeptNo 30.
6. Count those records having non null values in
Job
1. Display highest salary.
2. Display maximum sal of managers.
3. Display name of TOPPER from table student.

SELECT MAX(Sal)
FROM Emp ;
SELECT MAX(Sal)
FROM Emp
WHERE Post = ‘Manager’ ;

SELECT MIN (Sal) FROM Emp


WHERE Post = ‘Clerk’ AND DeptNo = 10 ;

You might also like