Class XI (As Per CBSE Board) : Informatics Practices
Class XI (As Per CBSE Board) : Informatics Practices
syllabus
2020-21
Chapter 11
SQL
Informatics Practices
Class XI ( As per CBSE Board)
Visit : python.mykvs.in for regular updates
SQL
SQL is an acronym of Structured Query Language. It is a
standard language developed and used for accessing and
modifying relational databases.
The SQL language was originally developed at the IBM
research laboratory in San José, in connection with a project
developing a prototype for a relational database
management system called System R in the early 70s.
SQL is being used by many database management systems.
Some of them are:
MySQL
PostgreSQL
Oracle
SQLite
Microsoft SQL Server
Visit : python.mykvs.in for regular updates
SQL
MySQL Features
Open Source & Free of Cost:
It is Open Source and available at free of cost.
Portability:
Small enough in size to instal and run it on any types of Hardware
and OS like Linux,MS Windows or Mac etc.
Security :
Its Databases are secured & protected with password.
Connectivity
Various APIs are developed to connect it with many programming
languages.
Query Language
It supports SQL (Structured Query Language) for handling database.
MySql datatypes
numeric
decimal -decimal(<precision>, [<scale>]) [zerofill] For storing floating-
point numbers where precision is critical.
Int - int(<size>) [auto_increment] [unsigned] [zerofill]
A whole number, 4 bytes, with a maximum range of -2,147,483,648 to
2,147,483,647 (unsigned: 0 to 4,294,967, 295)
string
char-char(<size>) [binary]
Fixed length – for storing strings that won't vary much in size.
Range of 0 to 255, stores that amount in bytes
Varchar-varchar(<size>) [binary]
Variable length – for storing strings that will vary in size.
Range of 0 to 255, stores that amount in bytes, plus 1 byte
date
Date-Format: YYYY-MM-DD ,Example: 2006-09-23,Range of years 1000 to
9999
Name Purpose
SUM() Returns the sum of given column.
MIN() Returns the minimum value in the given column.
MAX() Returns the maximum value in the given column.
AVG() Returns the Average value of the given column.
COUNT() Returns the total number of values/ records as per given
column.
NOTE – groupby and having clause is not included in class xi syllabus but
aggregation functions are there.
Visit : python.mykvs.in for regular updates
MYSQL
Aggregate Functions & NULL
Consider a table Emp having following records as-
Null values are excluded while (avg)aggregate function is used
Emp
Code Name Sal
E1 Mohak NULL
E2 Anuj 4500
E3 Vijay NULL
E4 Vishal 3500
SQL Queries E5 Anil 4000 Result of query
mysql> Select Sum(Sal) from EMP; 12000
mysql> Select Min(Sal) from EMP; 3500
mysql> Select Max(Sal) from EMP; 4500
mysql> Select Count(Sal) from EMP; 3
mysql> Select Avg(Sal) from EMP; 4000
mysql> Select Count(*) from EMP; 5
Visit : python.mykvs.in for regular updates
MYSQL
Aggregate Functions & Group
An Aggregate function may applied on a column with DISTINCT or ALL keyword. If
nothing is given ALL is assumed.
Using SUM (<Column>)
This function returns the sum of values in given column or expression.
mysql> Select Sum(Sal) from EMP;
mysql> Select Sum(DISTINCT Sal) from EMP;
mysql> Select Sum ( S a l ) from EMP where City=‘Jaipur’;
mysql> Select Sum ( S a l ) from EMP Group By City;
mysql> Select Job, Sum(Sal) from EMP Group By Job;
Using MIN (<column>)
This functions returns the Minimum value in the given column.
mysql> Select Min(Sal) from EMP;
mysql> Select Min(Sal) from EMP Group By City;
mysql> Select Job, Min(Sal) from EMP Group By Job;