0% found this document useful (0 votes)
17 views49 pages

Xi Ip SM 2024-25

The document outlines a unit-wise syllabus for a computer science course, detailing topics such as computer systems, Python programming, database concepts, and emerging trends in technology. Each unit is assigned a specific number of marks, with Unit 1 focusing on computer systems, Unit 2 on Python, Unit 3 on databases and SQL, and Unit 4 on emerging technologies like AI and IoT. The total marks for the course are 70, with a breakdown of questions and weightage provided for each unit.

Uploaded by

Aryan Biswas
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)
17 views49 pages

Xi Ip SM 2024-25

The document outlines a unit-wise syllabus for a computer science course, detailing topics such as computer systems, Python programming, database concepts, and emerging trends in technology. Each unit is assigned a specific number of marks, with Unit 1 focusing on computer systems, Unit 2 on Python, Unit 3 on databases and SQL, and Unit 4 on emerging technologies like AI and IoT. The total marks for the course are 70, with a breakdown of questions and weightage provided for each unit.

Uploaded by

Aryan Biswas
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
You are on page 1/ 49

Unit Wise syllabus

Distribution of Marks

Unit No. Unit Name Marks


1 Introduction to Computer System 10
2 Introduction to Python 25
3 Database concepts and the Structured Query Language 30
4 Introduction to the Emerging Trends 5

Unit 1: Introduction to Computer System


Introduction to computer and computing: evolution of computing devices, components of a computer
system and their interconnections, Input/output devices.
Computer Memory: Units of memory, types of memory – primary and secondary, data deletion, its recovery
and related security concerns.
Software: purpose and types – system and application software, generic and specific purpose software.

Unit 2: Introduction to Python


Basics of Python programming, Python interpreter - interactive and script mode, the structure of a
program, indentation, identifiers, keywords, constants, variables, types of operators, precedence of
operators, data types, mutable and immutable data types, statements, expressions, evaluation and
comments, input and output statements, data type conversion, debugging.
Control Statements: if-else, for loop
Lists: list operations - creating, initializing, traversing and manipulating lists, list methods and built-in
functions.
Dictionary: concept of key-value pair, creating, initializing, traversing, updating and deleting elements,
dictionary methods and built-in functions.

Unit 3: Database concepts and the Structured Query Language


Database Concepts: Introduction to database concepts and its need, Database Management System.
Relational data model: Concept of domain, tuple, relation, candidate key, primary key, alternate key
Advantages of using Structured Query Language, Data Definition Language, Data Query
Language and Data Manipulation Language, Introduction to MySQL, creating a database using MySQL, Data
Types
Data Definition: CREATE TABLE
Data Query: SELECT, FROM, WHERE.
Data Manipulation: INSERT

Unit 4: Introduction to the Emerging Trends


Artificial Intelligence, Machine Learning, Natural Language Processing, Immersive experience
(AR, VR), Robotics, Big data and its characteristics, Internet of Things (IoT), Sensors, Smart
cities, Cloud Computing and Cloud Services (SaaS, IaaS, PaaS); Grid Computing, Block chain
technology.
XI IP CBSE BLUEPRINT 2022-23
Marks Section

Weightage
Unit and Topic 1 2 3 5 4 A B C D E

Unit 1: Introduction to Computer


10
System
Introduction to computer and
computing,evolution of computing
devices, components of a computer 1 1 3 1 21
system and their interconnections,
Input/output devices.
Computer Memory:Units of memory,
types of memory – primary and 1 1 3 7 25
secondary, data deletion, its recovery and
related security concerns.
Software: purpose and types – system
and application software, generic and 1 1 4 10 26
specific purpose software.

Unit 2: Introduction to Python 25


Basics of Python programming, Python
interpreter - interactive and script mode,
the structure of a program, indentation,
1 2 24
identifiers, keywords, constants,
variables, types of operators, precedence
of operators.

data types, mutable and immutable data


types, statements, expressions, evaluation 1 1 4 2 27
and comments, input and output
statements, data type conversion,
debugging.

Control Statements: If-elif-else, while and 1 19


1 1 1 6 28
for loop, break,continue and pass. 7 19

Lists: list operations - creating,


initializing, traversing and manipulating 1 1 1 7 6 22 34
lists, list methods and functions.
1 1 6 12 31
Dictionary:concept of key-value pair,
creating, initializing, traversing, updating
and deleting 31
elements, dictionary methods and built-in
functions.
Unit 3: Database concepts and the 30
Structured Query Language
Database Concepts: Introduction to 3
database concepts and its need, Database 2 2
Management System. 14

Relational data model: Concept of 9


domain, tuple, relation, candidate key, 2 2
primary key, alternate key 15
MySQL Intro:Advantages of using
Structured Query Language, Data 11 30
Definition Language, Data Query
Language and Data Manipulation 2 1 5
Language, Introduction to MySQL,
16 30
creating a database using MySQL , Data
Types

DDL:CREATE TABLE 1 1 1 8 5 20 32
DQL: SELECT, FROM, WHERE. 1 1 6 13 23 33

DML: INSERT 1 1 1 7 8 23 33 35
Unit 4: Introduction to the Emerging 5
Trends
Artificial Intelligence, Machine Learning,
Natural Language Processing, Immersive 4 29
experience (AR, VR), Robotics, Big data
and its characteristics,.
2 1 5
Internet of Things (IoT), Sensors, Smart
cities, Cloud Computing and Cloud 18 29
Services (SaaS, IaaS, PaaS); Grid
Computing, Block chain technology.
NUMBER OF QUESTION 18 7 5 3 2 35

TOTAL MARKS 18 14 15 15 8 70
Unit 1: Introduction to Computer System
- Introduction to computer and computing: evolution of computing devices,
components of a computer system and their interconnections, Input/output
devices.
- Computer Memory: Units of memory, types of memory – primary and secondary,
data deletion, its recovery and related security concerns.
- Software: purpose and types – system and application software, generic and
specific purpose software.

1.1 Introduction to Computer System


The word originates from the Latin word “Computare” which means “to calculate”.
Earlier computers were used as calculating devices.
A computer is an electronic device that accepts data as input from users and gives the
output after processing them.

1.2 Evolution of computing devices


As mentioned at the beginning earlier computers were used to perform simple
calculations. Some of the early calculating devices also one of the important factors of
Introduction to Computer System, and they are as follows:

Abacus
It was the first calculating device with wooden frames along with beams sliding
on wires. It was used to perform basic arithmetic operations such as addition,
subtraction, multiplication, and division. It is also used to teach at early age
schools to count numbers.

Napier’s Bones
It was made by a Scottish mathematician named Sir John Napier in 1616. It had
numbers carved on bones or strips of wood. It was also used for simple
calculations. In addition to this it was used for calculating the root of the number.

Pascaline
It was invented by Blaise Pascal a French mathematician in 1641. It was the first
mechanical calculator. It has a rectangular box with movable wheels. It was also
used for simple calculations up to hundreds and thousands.

Difference Engine
It was invented by Charles Babbage in the Nineteenth Century. It was used to
prepare mathematical tables.

Analytical Engine
It was considered as the first-generation computer invented by Charles Babbage.
It had some basic elements such as input, output, and memory devices.

1.3 Generations of computers – Computer evolution started with technology evolution.


Each and every generation used different components in computers for storage of data,
performing the tasks. There are five generations of computers:

Note: There are variations in generation duration by different sources.


First Generation Computers
● First generations of computers were very large in size as well as less
memory storage.
● It was very expensive at that time.
● To input data, there were punch cards and paper tape.
● Vacuum Tubes were used to store data in this generation of computers.
● Ex.
○ Mark – I was developed by Howard H. Aiken, ENIAC (Electronic
Numerical Integrator and Computer) developed by John Presper
Eckert and John W. Mauchly.
○ EDSAC(Electronic Delay Storage Automatic Calculator)
developed by professor M. Wilkes of Cambridge University,
○ UNIVAC I(Universal Automatic Computer) developed by J.
Presper Eckert and John Mauchly.

Second Generation Computers


● They were small in size compared to the first generation’s computers.
● Transistors were used to store data on these computers.
● Punch cards were used for input.
● Ex. IBM 1401 and RCA 501

Third Generation Computers


● They were smaller in size, faster, cheaper, and efficient than earlier ones.
● They used Integrated Circuits (ICs) and
● Keyboard to input.
● They used monitors to display output.
● Ex. IBM 360 series and 370 Series

Fourth Generation Computers


● They are the modern computers we use today.
● They have microprocessors consisting of ICs (VLSI) on a single chip called
CPU.
● They have more storage power and computing power.
● Ex. IBM PC , Apple Macintosh, Dell, HP etc

Fifth Generation Computers


● They have high storage capacity, high speed, and are capable of
performing sophisticated tasks.
● They involve Artificial Intelligence for computing.
● Wearables
● IOT Devices

1.4 Computer system interconnection


Since a computer follows Input-Process-Output cycle, thus components of computer are
categorized in three parts:

1. Input Devices
2. Central Processing Unit
3. Output Devices
The basic component structure of computer is as shown below:

As shown in the diagram , various parts of the computer interact together to make the
computer work. You input data to the computer by using input devices and the CPU acts
upon this data and provides output which is made available to the user by using the
output device.

Input devices
Input device is responsible for taking input from the user and providing it to the
computer. Some most commonly used input devices are
● Keyboard
● Mouse
● Microphone
● Webcam
● Scanner
● Barcode reader
● Light pen
● Joystick

Output devices
Output device is responsible for providing and displaying output to the user.
Some most commonly used output devices are:
● Monitor- LED Monitor, LCD Monitor, CRT Monitor
● Printer- Impact Printer (Inkjet, Dot-Matrix), Non-Impact Printer
(Laser, Inkjet)
● Plotter
● Speaker

CPU (Central Processing Unit)


The CPU is the control centre of the computer. It understands the instructions
and carries out operations on the computer accordingly. It is the brain of a
computer and controls the activity performed by the computer.
The CPU has three components:
● ALU (Arithmetic and Logical Unit)
● MU (Memory Unit)
● CU (Control Unit)

ALU (Arithmetic and Logical Unit) ALU is a component which is responsible for
all the arithmetic or logical operations done on the data. Arithmetic operations are
the basic mathematical calculations. Logical operations are basically comparison
operations involving comparing data.
CU (Control Unit) The control unit is a component which controls the flow of
data and operations in a computer. It acts as a manager and instructs and
coordinates all the components of the CPU to perform their respective task.

1.5 MU (Memory Unit) Memory unit is a component which is responsible


for storing all data and information and instructions. Memory of a
computer is more like a predefined working space where it temporarily
keeps information and data to facilitate its performance. When the task is
performed, it clears its memory and memory space is then available for the
next task to be performed. This memory is often called the main memory.
There are two types of memory: Primary and secondary memory

Primary Memory: Primary memory also known as VOneertile memory that is


temporary as it loses its contents when the computer’s power is turned off. It is internal
memory that is accessed directly by the processor. Following are the Primary memory:

- RAM: Random Access Memory is the memory that the computer uses for storing
the programs and their data while working on them. We can either read data
from the RAM or write onto it. Hence it is called read/write memory.

- ROM: Read Only Memory is used to store the data about the hardware which
does not require frequent updates, for example startup programs that load
Operating System into RAM. ROM is non-vOneertile memory. We can only read
data from the ROM and hence called read only memory.

- Cache Memory: Catch memory is very high speed memory which is placed
between processor and RAM to speed up the operations of CPU. Generally it
stores the copies of data frequently accessed from RAM.

Secondary Memory: Secondary memory also known as non-vOneertile memory stores


data and instructions permanently for future use. It is slower than primary memory but
cannot be accessed by the processor directly.
Example of Secondary Memory are :
● Hard Disk
● CD/DVD
● USB Flash Drive
● Memory Card
● Memory Unit

bit(b) is the smallest unit of memory. A bit can either have 1 or 0.


Byte(B) is a unit of memory used to measure the amount of space consumed by data or
instructions in memory. 8 bits 1 Byte
Nibble: 4 bits1 nibble

Memory size conventions


1 Kilobyte - 1024 Bytes
1 Megabyte - 1024 KB
1 Gigabyte - 1024 MB
1 Terabyte - 1024GB
1 Petabyte - 1024 TB
1 Exabyte - 1024 PB
1.6 Data:
- Data Capturing: Data capturing refers to the process of collecting or inputting
data from different sources. To input data different input devices can be used
such as keyboard, scanner, camera, bar code reader etc. data capturing might be
a complex process due to nonuniformity in data.

- Data Storage: Data storage refers to the process of storing captured data for
future use. There are many different types of storage devices available which can
be used to store data. Nowadays due to the rise in computers, Internet and
Technology large volumes of data being produced and hence the storage device
should be of large capacity and updated regularly. to store large amounts of data,
Server can be deployed or Cloud computing can also be used.

- Data Retrieval: Data Retrieval refers to accessing or fetching data from storage
devices as per requirement. Due to the large volume of data nowadays, systems
must have good quality and effective programs in order to access data at
minimum time.

- Deleting data refers to erasing data from storage devices. There can be many
reasons for deleting data such as system crash, accidental deletion, and illegal
deletion by hackers/mischief mongers. When data is deleted from storage media,
only the status (address entry) of data is changed and that space is shown empty
to the user without deleting data actually.

- Data recovery is the process of accessing deleted, lost or corrupted data from
storage devices. Deleted data can only be recovered when memory space of
deleted data has not been overwritten with new data.

- Using Backup: A backup is a utility software to backup specific data before


deletion. Users have to take their data backup at regular intervals to avoid stress
caused by accidental deletion. To restore backup data users must use the restore
tool provided by windows. Users can only restore those data in which backup
has been taken.

The infernal devices: The computer system has the following internal devices:
● Motherboard: The motherboard is a circuit board of the computer system. All
the devices are connected with this board internally or externally. It provides
slots, connectors, and ports to connect devices.
● SMPS: It stands for switch mode power supply. It is attached with a power cable
from outside and connected with the motherboard through a connector.
● Hard Disk: A hard disk is the main storage device of the computer. It is
connected to the slot on the motherboard and to SMPS.
● CPU: The CPU is connected or attached to the CPU socket. On top of the CPU, a
fan is attached to provide cooling to the CPU.
● RAM: RAMs are attached to RAM slots on the motherboard.
● Ports: Ports allow one to attach external devices to the computer. These ports
are generally found at the backside of the cabinet. Ports have either halls or pins
to attach a device.

1.7 Software: Software is a set of programs that instruct hardware to what to and
how to do. It makes hardware functional to achieve a common objective. Some examples
of software are Windows 10, Macintosh, MySQL, MS Word, Excel, Games etc.
Types of software:
1. System software
2. Application software
1. System Software: System software manages computer systems. It is software
that controls and coordinates all internal activities of a computer system.

System software can be categorized as


A. Operating System
B. Utility Software
C. Device Driver

A. Operating System: Operating System acts as an interface between user


and machine. It is set of programs that –
● Manages hardware resources
● Manage memory
● Display result in monitor
● Control all hardware component attached to computer system
● Read data through input devices
● Example: Windows 10, Macintosh, Ubuntu, DOS etc.

B. Utility software: It is system software that helps you to configure and


optimise and maintain a computer. Examples of utility software are- Disk
Cleaner, File Backup Utility, Antivirus, Firewall, Disk Defragmenter etc.

C. Device Driver: Device driver is software which controls a particular type


of hardware attached with a computer. It acts as an interpreter between
particular hardware and computer systems.

2. Application Software: Application Software helps in providing a graphical


user interface to the user to operate the computer for different functionality. The
user may use the computer for browsing the internet, accessing to email service,
attending meetings, and playing games.
Different high-level languages are used to build application software. They
basically lie over system software. They are really utilized by end-user just as have
explicit usefulness or undertakings which they are intended to perform. This
application software is regularly evolved through custom software improvement,
in light of prerequisites of clients.

Types Of Application Software :


1. General Purpose Software
2. Custom Made Software

General Purpose Software :


The Software is developed to serve the requirements of a large number of
people on a daily basis. This software is eventually used on a regular basis
by every user. These are the reasons why this software is cheaper than any
other software. Some of the examples are: MS Word, Google Docs, Google
Drive, Gmail, Netflix

Custom Made Software :


Software which is developed to serve the requirement of the particular
user is defined as custom-made software. Most software companies work
on the basis of the requirement of the user to build custom software. Some
of the examples are:Desktop Software Application, Mobile Application Web
Application, Database Software.
Advantages of Application Software :
- Application Software packages are written by software architects
and the content is of great quality.
- They have large availability and are generally cheaper when
compared to the other packages.
- The application software meets the exact needs of the user, because
they are designed specifically for the single intention of the user, the
user knows that he has to use one specific software to accomplish
his task.

Disadvantages of Application Software :


- Some software that is designed specifically for a certain business,
may not be compatible with other general software because each
software serves a different purpose.
- The development of software is time-consuming because it needs
constant communication between the developer and the customer.
This delays the entire development process, which can lead to more
spending on utilities.
Unit 2: Introduction to Python
- Basics of Python programming, Python interpreter - interactive and script mode, the
structure of a program, indentation, identifiers, keywords, constants, variables, types
of operators, precedence of operators, data types, mutable and immutable data
types, statements, expressions, evaluation and comments, input and output
statements, data type conversion, debugging.
- Control Statements: if-else, for loop
- Lists: list operations - creating, initialising, traversing and manipulating lists, list
methods and built-in functions.
- Dictionary: concept of key-value pair, creating, initialising, traversing, updating and
deleting elements, dictionary methods and built-in functions.

2.1 Python Fundamentals


1. What is Python:- Python is a general-purpose, high level programming language. It
was created by Guido van Rossum, and released in 1991.
·In order to communicate with a computer system, we need a computer programming
language. This language may be C, C++, Java, Python or any other computer language.
Here we will discuss Python.
·Python is inspired by two languages – (i) ABC language which was an optional language
of BASIC language. (ii)Modula-3
2. Why Python:-
· Platform Independent (Cross-Platform)
· Free and Open Source
· simple syntax similar to the English language.
· fewer lines than some other programming languages. interpreted Language.
· Python can be treated in a procedural way, an object-orientated way. (OOL and POL.)
3. What can Python do?:- It is possible to develop various Apps/ Software’s with Python
like–
· Web development
· Machine learning
· Data Analysis
· Scripting
· Game development.
· Embedded applications
· Desktop applications
4. How To Use Python?:-
4.1 Python can be downloaded from www.python.org. (Standard Installation)
4.2. It is available in two versions- • Python 2.x • Python 3.x (It is in Syllabus)
OR
Apart from above standard Python. We have various Python IDEs and Code Editors. Some
of them are as under:-
(i) Anaconda Distribution:- free and open-source distribution of the Python. having
various inbuilt libraries and tools like jupyter Notebook, Spyder etc
(ii) PyCharm (iii) Canopy
(iv) Thonny (v) Visual Studio Code
(vi) Eclipse + PyDev (vii) Sublime Text
(viii )Atom (ix) GNU Emacs
(x) Vim (xi) Spyder and many more...
5. Python Interpreter - Interactive And Script Mode :-
We can work in Python in Two Ways:-
(i) Interactive Mode
(ii) Script Mode
(i) Interactive Mode:- it works like a command interpreter as shell prompt works in DOS
Prompt or Linux. On each (>>>) symbol we can execute one by one command.
(ii) Script Mode:- it used to execute the multiple instruction (complete program) at once.

6. Python Character Set:-


Character Set is a group of letters or signs which are specific to a language. Character set
includes letter, sign, number and symbol.
· Letters: A-Z, a-z
· Digits: 0-9
· Special Symbols: _, +, -, *, /, (, #,@, {, } etc.
· White Spaces: blank space, tab, carriage return, newline, formfeed etc.
· Other characters: Python can process all characters of ASCII and UNICODE.

7. Python Tokens:-
Token is the smallest unit of any programming language. It is also known as Lexical Unit.
Types of token are
i. Keywords
ii. Identifiers (Names)
iii. Literals
iv. Operators
v. Punctuators

7.1 Keywords:- Keywords are reserved words. Each keyword has a specific meaning to
the Python interpreter. As Python is case sensitive, these cannot be used as identifiers,
variable name or any other purpose keywords must be written exactly as given below:-

7.2 Identifiers:- In programming languages, identifiers are names used to identify a


variable, function, or other entities in a program. The rules for naming an identifier in
Python are as follows:
· The name should begin with an uppercase or a lowercase alphabet or an underscore
sign (_).
· This may be followed by any combination of characters a-z, A-Z, 0-9 or underscore
(_). Thus, an identifier cannot start with a digit.
· It can be of any length. (However, it is preferred to keep it short and meaningful).
· It should not be a keyword or reserved word.
· We cannot use special symbols like !, @, #, $, %, etc. in identifiers.

Legal Identifier Names Example: myvar my_var _my_var myVar myvar2


Illegal Identifier Names Example:- 2myvar my-var my var=

7.3 Literals/ Values:- Literals are often called Constant Values. Python permits following
types of literals -
a. String literals - “Rishaan”
b. Numeric literals – 10, 13.5, 3+5i
c. Boolean literals – True or False
d. Special Literal None
e. Literal collections
7.4 Operators:- An operator is used to perform specific mathematical or logical
operations on values. The values that the operator works on are called operands. Python
supports following types of operators -
Unary Operator
•Unary plus (+)
•Unary Minus (-)
•Bitwise complement (~)
•Logical Negation (not)
Binary Operator
•Arithmetic operator (+, -, *, /, %, **, //)
•Relational Operator(<, >, <=, >=, ==,!)
•Logical Operator (and, or)
•Assignment Operator (=, /=, +=, -=, *=, %=, **=, //=)
•Bitwise Operator (& bitwise and, ^ bitwise xor,|bitwise or)
•Shift operator (<< shift left, >> shift right)
•Identity Operator (is, is not)
•Membership Operator (in, not in)
7.5 Punctuators:-
Punctuators are symbols that are used in programming languages to organize sentence
structure, and indicate the rhythm and emphasis of expressions, statements, and
program structure. Common punctuators are: „ “ # $ @ []{}=:;(),

8. Variable:-
· Variables are containers for storing data values.
· Unlike other programming languages, Python has no command for declaring a
variable.
· A variable is created the moment you first assign a value to it.
Example:-
x5
y "John"
print(x)
print(y)
· Variables do not need to be declared with any particular type and can even change
type after they have been set.
x 4 # x is of type int
x "Sally" # x is now of type str
print(x)
· String variables can be declared either by using single or double quotes:
x "John"
# is the same as
x 'John'

Variable Names
A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume).
Rules for Python variables:
· A variable name must start with a letter or the
· underscore character
· A variable name cannot start with a number
· A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
· Variable names are case-sensitive (age, Age and AGE are three different variables)

Output Variable:-
The Python print statement is often used to output variables. To combine both text and a
variable, Python uses the , character:
x "awesome"
print("Python is " , x)
Display Multiple variable:-
x "awesome“
y=56
print(“Value of x and y is=" ,x,y)

9. Data Type:-
Every value belongs to a specific data type in Python. Data type identifies the type of data
which a variable can hold and the operations that can be performed on those data.

Data Types in Python:-


· Numbers :- int, float and complex.
· List :- [5, 3.4, "New Delhi", "20C", 45]
· Tuple :- (10, 20, "Apple", 3.4, 'a')
· Strings :- str 'Hello Friend'
· Set:- {2,6,9}
· Dictionary:- {'Fruit':'Apple', 'Climate':'Cold', 'Price(kg)':120}

Mutable and Immutable data type


Mutable:- The values stored can be changes, Size of object can be changed, e.g. List,
Dictionary
Immutable:- The value stored can not be changed, Size can not be changed, e.g. Tuple,
String

10. Expression in python:- An expression is a combination of values, i.e., constant ,


variable and operator.
e.g. Expression 6-3*2+7-1 evaluated as 6

11. Precedence and associativity of Arithmetic Operators:- Precedence and


associativity helps to evaluate an expression. Let’s take a look with following example:

Operator Description Associativity

() Parentheses left-to-right

** Exponent right-to-left

* / % Multiplication/division/modulus left-to-right

+ – Addition/subtraction left-to-right

<< >> Bitwise shift left, Bitwise shift right left-to-right

< <= Relational less than/less than or equal to


left-to-right
> >= Relational greater than/greater than or equal to
== != Relational is equal to/is not equal to left-to-right

is, is not Identity


left-to-right
in, not in Membership operators

& Bitwise AND left-to-right

^ Bitwise exclusive OR left-to-right

| Bitwise inclusive OR left-to-right

not Logical NOT right-to-left

and Logical AND left-to-right

or Logical OR left-to-right

= Assignment
+= -= Addition/subtraction assignment
*= /= Multiplication/division assignment
right-to-left
%= &= Modulus/bitwise AND assignment
^= |= Bitwise exclusive/inclusive OR assignment
<<= >>= Bitwise shift left/right assignment
12. Comments in python:- Comments are non-executable statements of python. It
increases the readability and understandability of code.
Types of comment –

i. Single line comment (#) – comments only on a single line.


e.g. a=7 # 7 is assigned to variable ‘a’
print(a) # displaying the value stored in ‘a’
ii. Multi-line comment (‘‘‘………..’’’) – Comments multiple line.
e.g. ‘‘‘Program -1
A program in python to store a value in
variable ‘a’ and display the value stored in it.’’’
a=7
print(a)

13. Input and output in python:-

input ( ) method - It is used to take input from the user.

print ( ) method – It is used to display messages or result in output.

Example:-
Name input (“Enter your name : ”)
Marks int(input (“Enter your marks ”))
print(“Your name is ”, Name)
print(“You got ”, Marks, “ marks”)

14. Debugging:- Debugging is a process of locating and removing errors from a program.
Types of errors:
a. Compile Time Error: (i) Syntax Error (ii) Semantics Error
b. Run Time Error
c. Logical Error

a. Compile Time Error: Compile time errors are those errors that occur at the time of
compilation of the program. There are two types of compile time errors:
i. Syntax Error: These errors occur due to violation of grammatical rules of a
programming language.
Example:
x=10
y=20
if(x<y):
Print(“a is greater than b”) # Syntax error, P is capital in Print statement

b. Semantics Error: Semantic errors occur when the statements written in the
program are not meaningful.
Example:
a=10
b=20
a+b = c # expression cannot come on the left side of the assignment operator

b. Run Time Error: Errors that occur during the execution or running the program are
known as run time errors. When a program “crashes” or “abnormally terminated” during
the execution, then these type errors are run time errors.
Example: When a loop executes infinite time.
a=1
while a<5: # value of a is always less than 5, infinite loop
print(a)
a=a-1

c. Logical Error: These types of errors occur due to wrong logic. When a program
successfully executes but giving wrong output, then it is known as logical error.
Example:
a=10
b=20
c=30
average=(a+b+c)/2 # wrong logic to find the average
print(average)
OUTPUT:
30.0

Steps to debug a program:


a. Carefully follow the syntax of a language
b. Spot the origin of error
c. Read the type of error and understand it well
d. Use intermediate print statements to know the value and type of a variable
e. Trace the code carefully
Note: There are debuggers available in almost all sophisticated python IDEs. They are
implemented with pdb. To know more, read the official documentation here:
https://docs.python.org/3/library/pdb.html

15. Supplementary Reading:


Exception handling in python: (To deal with run time errors/exceptions)
Exception: The unusual and unexpected condition other than syntax or logical errors,
encountered by a program at the time of execution, is called exception.

The purpose of the exception handling mechanism is to provide means to detect and
report an exceptional circumstance, so that appropriate action can be taken.
Exception handling in python can be done using try and except blocks.

Syntax:
try:
# Code that may generate an exception
except:
# Code for handling the exception

Example:
num1=int(input(“Enter first number :”))
num2=int(input(“Enter second number: “))
try:
r=num1/num2
print(“Result is :”, r)
except:
print(“Divided by zero”)

OUTPUT:
Enter first number : 30
Enter second number: 0
Divided by zero
2.2 Python Control Statements
In any programming language a program may execute sequentially, selectively or
iteratively. Every programming language provides constructs to support Sequence,
Selection and Iteration. In Python all these constructs can broadly be categorised in 2
categories.

Conditional Control Construct


( Selection, iteration)

Unconditional Control Construct


(pass, break,continue, exit(), quit())

Python have following types of control statements


1. Selection ( branching) Statement
2. Iteration ( looping) Statement
3. Jumping (break / continue)Statement

Python Selection Statements


Python have following types of selection statements
1. if statement
2. if else statement
3. Ladder if else statement (if-elif-else)
4. Nested if statement

If statements
This construct of a python program consists of one if condition with one block of
statements. When the condition becomes true then executes the block given below it.
Syntax:
if ( condition):
Statement(s)
Example:
age=int(input(“Enter Age: “))
if ( age>=18):
print(“You are eligible for vote”)
if(age<0):
print(“You entered Negative Number”)

if - else statements
This construct of a python program consists of one if condition with two blocks. When
the condition becomes true then executes the block given below it. If the condition
evaluates the result as false, it will execute the block given below else.
Syntax:
if ( condition):
Statement(s)
else:
Statement(s)
Example
age=int(input(“Enter Age: “))
if ( age>=18):
print(“You are eligible for vote”)
else:
print(“You are not eligible for vote”)

Ladder if else statements (if-elif-else)


This construct of a python program consists of more than one if condition. When the first
condition evaluates the result as true then executes the block given below it. If the
condition evaluates the result as false, it transfers the control at the else part to test
another condition. So, it is a multi-decision making construct.
Syntax:
if ( condition-1):
Statement(s)
elif (condition-2):
Statement(s)
elif (condition-3):
Statement(s)
else:
Statement(s)
Example:
num=int(input(“Enter Number: “))
If ( num>=0):
print(“You entered positive number”)
elif ( num<0):
print(“You entered Negative number”)
else:
print(“You entered Zero ”)

Nested if statements
It is the construct where one if condition takes part inside of another if condition. This
construct consists of more than one if condition. Block executes when the condition
becomes false and the next condition evaluates when the first condition becomes true.
So, it is also a multi-decision making construct.
Syntax:
if ( condition-1):
if (condition-2):
Statement(s)
else:
Statement(s)

Example:
num=int(input(“Enter Number: “))
if ( num<=0):
if ( num<0):
print(“You entered Negative number”)
else:
print(“You entered Zero ”)
else:
print(“You entered Positive number”)
Python Iteration Statements
The iteration (Looping) constructs mean to execute the block of statements again and
again depending upon the result of condition. This repetition of statements continues till
condition meets True result. As soon as the condition meets a false result, the iteration
stops.
Python supports following types of iteration statements
1. while
2. for
Four Essential parts of Looping:
i. Initialization of control variable
ii. Condition testing with control variable
iii. Body of loop Construct
iv. Increment / decrement in control variable

Python while loop


The while loop is a conditional construct that executes a block of statements again and
again till the given condition remains true. Whenever the condition meets result false
then loop will terminate.

Syntax:
Initialization of control variable
while (condition):
…………………..
Updation in control variable
..…………………

Example: Sum of 1 to 10 numbers.


num=1
sum=0
while(num<=10):
sum + num
num + 1
print(“The Sum of 1- 10 numbers: “,sum)

Python range( ) Function


The range() function returns a sequence of numbers, starting from 0 by default, and
increments by 1 (by default), and ends at a specified number.

Syntax:
range( start value, stop value, step value )
Where all 3 parameters are of integer type

● Start value is Lower Limit


● Stop value is Upper Limit
● Step value is Increment / Decrement

Note: The Lower Limit is included but Upper Limit is not included in result.
Example
range(5) => sequence of 0,1,2,3,4
range(2,5) => sequence of 2,3,4
range(1,10,2) => sequence of 1,3,5,7,9
range(5,0,-1) => sequence of 5,4,3,2,1
range(0,-5) => sequence of [ ] blank list
(default Step is +1)
range(0,-5,-1) => sequence of 0, -1, -2, -3, -4
range(-5,0,1) => sequence of -5, -4, -3, -2, -1
range(-5,1,1) => sequence of -5, -4, -3, -2, -1, 0

Python for loop


A for loop is used for iterating over a sequence (that is either a list, a tuple, a string etc.)
With for loop we can execute a set of statements, and for loop can also execute once for
each element in a list, tuple, set etc.
Example: print 1 to 10 numbers
for num in range(1,11,1):
print(num, end=” “)
Output: 1 2 3 4 5 6 7 8 9 10

Un- Conditional Control Construct


(pass, break, continue, exit(), quit())

pass Statement (Empty Statement)


The pass statement does nothing, but it is used to complete the syntax of programming
concepts. Pass is useful in the situation where the user does not require any action but
syntax requires a statement. The Python compiler encounters a pass statement then it
does nothing but transfer the control in flow of execution.

Example
a=int(input("Enter first Number: "))
b=int(input("Enter Second Number: "))
if(b==0):
pass
else:
print("a/b=",a/b)

Jumping Statements
● break
● continue

break Statement
The jump- break statement enables you to skip over a part of code that is used in a loop
even if the loop condition remains true. It terminates to that loop in which it lies. The
execution continues from the statement which finds the loop terminated by break.

Continue Statement
Continue statement is also a jump statement. With the help of a continue statement, some
of the statements in the loop skipped over and started the next iteration. It forcefully stop
the current iteration and transfers the flow of control at the loop controlling condition.
2.3 LIST
Definition : A List is a collection of comma separated values within a square bracket.
Items in a list need not to be the same.

Features of list
• A List is used to store a sequence of values / items.
• All Elements of a list are enclosed in [ ] square brackets.
• Items / values are separated by comma.
• Lists are mutable (changeable) in python.

Different type of lists


# List of text
Fruit=['Mango','Orange','Apple']
#List of Characters
Grade=['A','B','C']
# List of integers
Marks=[75,63,95]
# List of floats
Amount=[101.11,125.81,99.99]
# List with different data types
Record=[75,'Mango',101.11]
# List within a List
list1=[2,3,[2,3]]
# List with text splitted into chars
list2=list('IP&CS')
#Empty list
list3=list()

Creation of list from user input


eval()– this method can be used to accept tuples from users. Which can be converted to
list, using the list() method.
E.g.
T=eval(input(“Enter a set of numbers ”))
print(“Tuple is ”,T)
L=list(T)
print(“List is ”,L)

Output
Enter a set of numbers 4,7,5,6,9,2
Tuple is(4,7,5,6,9,2)
List is=[4,7,5,6,9,2]

List Indexing,
List1 [12, 3, 43, 23, 33, 65]
Accessing elements from a list

Traversing of list elements (Iteration/Looping over a list)


List1=[12,3,43,23,33,65]
Method-1
List1 [12,3,43,23,33,65] both result in same O/P
for i in range(0,len(List1)): 12
print(List[i]) 3
43
Method-2 23
List1 [12,3,43,23,33,65] 33
for x in List1: 65
print(x)

SLICING : Accessing a part of a list is known as slicing.


-9 -8 -7 -6 -5 -4 -3 -2 -1

A M I T J A I N
0 1 2 3 4 5 6 7 8

List1 ['A', 'M', 'I', 'T', ' ','J','A', 'I', 'N']


Statement Output Explaination
print(List1[:]) ['A', 'M', 'I', 'T', ' ', 'J', 'A', 'I', 'N'] list_object[Start:End:Step]

print(List1[2:]) ['I', 'T', ' ', 'J', 'A', 'I', 'N']


Select from Start index to end-1
index, with jump of step for the
print(List1[:6]) ['A', 'M', 'I', 'T', ' ', 'J']
next and subsequent element
selection.
print(List1[0:4]) ['A', 'M', 'I', 'T']

print(List1[3:6]) ['T', ' ', 'J']

print(List1[-2:-5]) []

print(List1[-5:-2]) [' ', 'J', 'A']

print(List1[1:7:2]) ['M', 'T', 'J']


ADDITION OF ELEMENTS IN LIST: Two ways to add an item in the list

1. Append command
append( ) is used to add only one element at
a time.
ListF [44, 55]
ListF # [44, 55]
ListF.append(77)
ListF # [44, 55, 77]
ListF.append(88,88) # Error
ListF.append([88, 99]) # [44, 55, 77, [88, 99]]

2. Extend command
extend( ) is used to add one or more
elements
ListF [44, 55]
List F # [44, 55]
ListF.extend(77) # Error

ListF.extend([77]) # [44, 55, 77]

ListF.extend([88, 99]) # [44, 55, 77, 88, 99]

MODIFICATION /UPDATION OF ITEM


ListD[36, 46, 56, 66, 76] Output

ListD[2] # 56
ListD[2] 1000 # 56
ListD[2] # 1000
ListD # [36, 46, 1000, 66, 76]
ListD[2:3]400,500 # [36, 46, 400, 500, 66, 76]

DELETION OF ELEMENTS FROM LIST

Using del command O/P


List1=[44,55,66,77,88]
del List1[2]
print(List1) [44,55,77,88]
del List1[1:3]
print(List1) [44,88]

Using pop(index) method O/P


L1=['K', 'V', '4']
print(L1.pop( )) 4
print(L1.pop(1)) V
print(L1) [‘K’, ‘4’]
print(L1.pop(-1)) 4
OPERATIONS ON THE LIST
E.g. L1=[23,12,43,22,5,34]
L2=[4,3,5]

Sl. No. Operator For List Output


L1 & L2

1 Concatenation‘+’ L1+L2 [23, 12, 43, 22, 5, 34, 4, 3, 5]


2 Replication/ Repetition ‘*’ L2*3 [4,3,5,4,3,5,4,3,5]

3 Membership ‘ in ‘ and ‘ not in’ 43 in L1 True


(Check presence of element) 3 not in L2 False

METHODS / FUNCTIONS
E.g. L1=[23,12,43,23,5,34]
L2=[‘K’, ‘V’, ‘S’]

Sl. Method / Function Example Output


No. For given list
L1 & L2

1 index(item) L1.index(43) 2
To display index of an
item
2 insert(index, item) L2.insert(1, ‘A’) ['K','A','V','S']
To add an item at given
index
3 reverse() L2.reverse() [‘S’,‘V’,‘A’,‘K’]
Reverse the order of
elements
4 len(List) len(L1) 6
Returns length of list

5 sort() Ascending order ['A','K','S','V']


Arrange the elements in L2.sort()
ascending or descending
Order Descending order ['V','S','K','A']
L2.sort(reverse =True)
6 count(item) L1.count(23) 2
Counts frequency of an
item
7 remove(item) L2.remove(‘A’) [‘K’,’V’,’S’]
Remove the item
8 max(list) max(L1) 43
Returns maximum value

9 min(list) min(L1) 5
Returns minimum value
2.4 DICTIONARY
Key points: -
- Python Dictionaries are a collection of some key:value pairs.
- Python Dictionaries are unordered collection
- Dictionaries are mutable means values in a dictionary can be changed using its key
- Keys are unique.
- Enclosed within brace { }

Working with dictionaries


Creating Python # empty dictionary
Dictionary my_dict {}

# dictionary with integer keys


my_dict {1: 'apple', 2: 'ball'}

# dictionary with mixed keys


my_dict {'name': 'John', 1: [2, 4, 3]}

dict( ) method # using dict()


my_dict dict({1:'apple', 2:'ball'})
Accessing Elements my_dict {'name': 'Jack', 'age': 26}
from Dictionary print(my_dict['name'])
print(my_dict.get('age'))

get( ) method # Trying to access keys which doesn't exist returns None
print(my_dict.get('address'))

# KeyError
print(my_dict['address'])
Output: -
Jack
26
None
Traceback (most recent call last):
File "<string>", line 15, in <module>
print(my_dict['address'])
KeyError: 'address'
Changing and Adding # Changing and adding Dictionary Elements
Dictionary elements my_dict {'name': 'Jack', 'age': 26}

# update value
my_dict['age'] 27
print(my_dict)

# add item
my_dict['address']= 'Downtown'
print(my_dict)

Output: -
{'name': 'Jack', 'age': 27}
{'name': 'Jack', 'age': 27, 'address': 'Downtown'}
Removing elements # Removing elements from a dictionary
from Dictionary squares {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
pop( ) method # remove a particular item, returns its value
print(squares.pop(4))
print(squares)

popitem method( ) # remove an arbitrary item, return (key,value)


print(squares.popitem())
print(squares)

clear( ) method # remove all items


squares.clear()
print(squares)

del function # delete the dictionary itself


del squares

Output: -
16
{1: 1, 2: 4, 3: 9, 5: 25}
(5, 25)
{1: 1, 2: 4, 3: 9}
{}
len() – Finding dict={'Name':'Aman','Age':3}
number of items in print("Length: - ", len(dict))
dictionary OUTPUT
Length:- 2
keys() - returns all the x=dict(name=“Aman",age=37,country=“India")
available keys print(x.keys())
OUTPUT
dict_keys(['country','age','name'])
values()- returns all x=dict(name=“Aman",age=37,country=“India")
the available values print(x.values())
OUTPUT
dict_values(['India',37,'Aman'])
items()- return the list x=dict(name="Aman",age=37,country="India")
with all dictionary print(x.items())
keys with values. OUTPUT-
dict_items([('country','India'),('age',37),('name','Aman')])
update()- used to x=dict(name="Aman",age=37,country="India")
change the values of a d1=dict(age=39)
key and add new keys x.update(d1,state="Rajasthan")
print(x)
OUTPUT-
{'country':'India','age':39,'name':'Aman','state':'Rajasthan'}
fromkeys()i- is used keys={'a','e','i','o','u'}
to create dictionary value="Vowel"
from keys vowels=dict.fromkeys(keys,value)
print(vowels)
OUTPUT-
{'i':'Vowel','u':'Vowel','e':'Vowel','a':'Vowel','o':'Vowel'}
copy()- returns a x=dict(name="Aman",age=37,country="India")
shallow copy of the y=x.copy()
dictionary. print(y)
OUTPUT->{'country':'India','age':37,'name':'Aman'}
Dictionary #Membership Test for Dictionary Keys
Membership Test squares {1: 1, 3: 9, 5: 25, 7: 49, 9: 81}

in print(1 in squares)
not in print(2 not in squares)
print(49 in squares)

Output -
True
True
False
Iterating Through a # Iterating through a Dictionary
Dictionary squares {1: 1, 3: 9, 5: 25, 7: 49, 9: 81}
for i in squares:
print(squares[i])

Output-
1
9
25
49
81
Unit 3: Database concepts and the Structured
Query Language
- Database Concepts: Introduction to database concepts and its need, Database
Management System.
- Relational data model: Concept of domain, tuple, relation, candidate key, primary
key, alternate key
- Advantages of using Structured Query Language, Data Definition Language, Data
Query Language and Data Manipulation Language, Introduction to MySQL,
creating a database using MySQL, Data Types
- Data Definition: CREATE TABLE
- Data Query: SELECT, FROM, WHERE.
- Data Manipulation: INSERT

3.1 Database Concepts: Introduction to database concepts and its need,


Database Management System.

Manual Record Keeping System : A System where records are maintained by


hand, without using a computer system.
Advantages of Manual Record Keeping System :
1. It is less expensive.
2. Less risk of data loss.
3. No software specialised person is required.
Disadvantages of Manual Record Keeping System :
1. No sharing of data.
2. More chances of inconsistent data.
3. Making correction is very time consuming.

Electronic Record Keeping System : A System in which records are


maintained in computer system instead of in paper.
Advantages of Electronic Record Keeping System :
1. Less paper wastage.
2. Searching of record is very simple.
3. Easy to backup the documents.
Disadvantages of Electronic Record Keeping System :
1. More expensive.
2. More risk to data loss.
3. A Software specialised person is required to manage this system.

Database Management System : A database management system (DBMS) is a software


that can be used to create and manage databases. Some examples of open source and
commercial DBMS include MySQL, Oracle, PostgreSQL, SQL Server, Microsoft Access,
MongoDB etc.

3.2 Relational data model: Concept of domain, tuple, relation, candidate


key, primary key, alternate key
RDBMS:
RDBMS stands for Relational Database Management System. RDBMS is the basis
for SQL, and for all modern database systems like MS SQL Server, IBM DB2, Oracle,
MySQL, and Microsoft Access. The data in RDBMS is stored in database objects
called tables. A table is a collection of related data entries and it consists of
columns and rows.

Common Terms used in DBMS :


Attributes : The columns of a relation are the attributes which are also referred
to as fields.
Tuple : Each row of data in a relation (table) is called a tuple. It is also known as a
record.
Domain : It is a set of values from which an attribute can take a value in each row.
Usually, a data type is used to specify a domain for an attribute.
Degree : The number of attributes in a relation is called the Degree of the relation.
Cardinality : The number of tuples in a relation is called the Cardinality of the
relation.

Key Concepts in DBMS :


Database Schema : It is the skeleton of the database that represents the structure
(table names and their fields/columns),the type of data each column can hold,
constraints on the data to be stored (if any), and the relationships among the
tables.
Data Constraint : Certain restrictions or limitations on the type of data that can
be inserted in one or more columns of a table during table creation is called data
constraint. Constraints are used to ensure accuracy and reliability of data in the
database.
Meta-data or Data Dictionary :The database schema along with various
constraints on the data is stored by DBMS in a database catalog or dictionary,
called meta-data. A meta-data is data about the data.
Database Instance : When we define database structure or schema, state of
database is empty i.e. no data entry is there. After loading data, the state or
snapshot of the database at any given time is the database instance.
Query : A query is a request to a database for obtaining information in a desired
way. Query can be made to get data from one table or from a combination of tables.
Data Manipulation : Modification of database consists of three operations viz.
Insertion, Deletion or Update. Insertion means adding a new record in a table.
Deletion means removing an existing record from a table. Updation means editing
an existing record in a table.
Database Engine : Database engine is the underlying component or set of
programs used by a DBMS to create a database and handle various queries for data
retrieval and manipulation.

Three Important Properties of a Relation :In relational data model, following three
properties are observed with respect to a relation which makes a relation different from
a data file or a simple table.

Property-1 : imposes following rules on an attribute of the relation.


1. Each attribute in a relation has a unique name.
2. Sequence of attributes in a relation is immaterial.

Property-2 : imposes following rules on tuples of the relation.


1. Each tuple in a relation is distinct.
2. Sequence of tuples in a relation is immaterial.

Property-3 : imposes following rules on the state of a relation.


1. All data values in an attribute must be from the same domain (same data
type).
2. Each data value associated with an attribute must be atomic.
3. No attribute can have many data values in one tuple.
4. A special value Null is used to represent values that are unknown.

Keys in Relational Database :


Candidate Key : Those fields which can act as a primary key in a table are called
candidate Key.
Primary Key : A field which uniquely identifies each and every record in the table
is called primary key.
Composite Primary Key : If no single attribute in a relation is able to uniquely
identify the tuples, then more than one attribute is taken together as primary key.
Such a primary key consisting of more than one attribute is called Composite
Primary key.
Foreign Key : A foreign key is used to represent the relationship between two
relations. A foreign key is an attribute whose value is derived from the primary
key of another relation.
Note: In some cases, foreign key can take a NULL value if it is not part of the primary key
of the foreign table. The relation in which the referenced primary key is defined is called
primary relation or master relation.

3.3 INTRODUCTION TO MYSQL


-Advantages of using Structured Query Language, Data Definition Language, Data Query
Language and Data Manipulation Language, Introduction to MySQL, creating a database
using MySQL, Data Types
-Data Definition: CREATE TABLE
-Data Query: SELECT, FROM, WHERE.
-Data Manipulation: INSERT

What is MySQL?:
MySQL is a open source Relational Database Management System. MySQL is very fast
reliable and flexible Database Management System. It provides a very high performance
and it is multi threaded and multi user Relational Database management system.

MySQL Features
1. MySQL are very fast and much reliable for any type of application.
2. MySQL is very Lightweight application.
3. MySQL command line tool is very powerful and can be used to run SQL queries
against database.
4. MySQL supports indexing and binary objects.
5. It is allow changes to structure of table while server is running.
6. MySQL has a wide user base.
7. It is a very fast thread-based memory allocation system.
8. MySQL Written in C and C++ language.
9. MySQL code is tested with different compilers.
10. MySQL is available as a separate program for use in a client/server network
environment.

Advantages of MySql:
● Reliability and Performance : MySQL is very reliable and high performance
relational database management system. It can used to store many GB's of data
into database.
● Open Source: MySQL source code is available that's why now you can recompile
the source code.
● Cross-Platform support: MySQL supports more then twenty different platform
including the major Linux distribution .Mac OS X, Unix and Microsoft windows.
Keep in Mind That...
● SQL is not case sensitive in windows but it is if you use linux based environment.
● Semicolon after SQL Statements

Classification of SQL statements


SQL provides many different types of commands used for different purposes. SQL can be
divided into following parts:
1. Data Manipulation Language (DML) commands
2. Data Definition Language (DDL) commands.
3. Transaction Control Language (TCL)- Not part of our syllabus

1. DML commands: A DML is a language that enables users to access manipulated data
as organized by the appropriate data model.
● SELECT - extracts data from a database (DQL)
● UPDATE - updates data in a database Not part of our syllabus
● DELETE - deletes data from a database Not part of our syllabus
● INSERT INTO - inserts new data into a database
2. DDL commands: The DDL commands, as the name suggests, allow you to perform
tasks related to data definition. The DDL part of SQL permits database tables to be created
or deleted. The most important DDL statements in SQL are:
● CREATE DATABASE - creates a new database
● ALTER DATABASE - modifies a database Not part of our syllabus
● CREATE TABLE - creates a new table
● ALTER TABLE - modifies a table Not part of our syllabus
● DROP TABLE - deletes a table Not part of our syllabus

MySQL Data Types


In MySQL there are three main data types: text, number, and Date/Time,
Text types:
Data type Description

CHAR(size) Holds a fixed length string (can contain letters, numbers, and special
characters). The fixed size is specified in parenthesis. Can store up to
255 characters

VARCHAR(size) Holds a variable length string. The maximum size: up to 255


characters. Note: If you put a greater value than 255 it will be converted
to a TEXT type

TEXT Holds a string with a maximum length of 65,535 characters

Number types:
Data type Description

INT(size) -2147483648 to 2147483647 normal. 0 to 4294967295


UNSIGNED*. The maximum number of digits may be specified in
parenthesis

FLOAT(size,d) A small number with a floating decimal point. The maximum


number of digits may be specified in the size parameter. The
maximum number of digits to the right of the decimal point is
specified in the d parameter

DECIMAL(size,d) A DOUBLE stored as a string , allowing for a fixed decimal point. The
maximum number of digits may be specified in the size parameter.
The maximum number of digits to the right of the decimal point is
specified in the d parameter
*The integer types have an extra option called UNSIGNED. Normally, the integer goes from an
negative to positive value. Adding the UNSIGNED attribute will move that range up so it starts at
zero instead of a negative number.
Date types:
Data type Description

DATE() A date. Format: YYYY-MM-DD


Note: The supported range is from '1000-01-01' to '9999-12-31'

DATETIME() *A date and time combination. Format: YYYY-MM-DD HH:MM:SS


Note: Range is from '1000-01-01 00:00:00' to '9999-12-31 23:59:59'

TIMESTAMP() *A timestamp. TIMESTAMP values are stored as the number of seconds


since the Unix epoch ('1970-01-01 00:00:00' UTC). Format: YYYY-MM-
DD HH:MM:SS Range is from '1970-01-01 00:00:01' UTC to '2038-01-09
03:14:07' UTC

TIME() A time. Format: HH:MM:SS


Note: The supported range is from '-838:59:59' to '838:59:59'

YEAR() A year in two-digit or four-digit format.


Note: Values allowed in four-digit format: 1901 to 2155. Values allowed
in two-digit format: 70 to 69, representing years from 1970 to 2069
*Even if DATETIME and TIMESTAMP return the same format, they work very differently. In an
INSERT or UPDATE query, the TIMESTAMP automatically set itself to the current date and time.
TIMESTAMP also accepts various formats, like YYYYMMDDHHMMSS, YYMMDDHHMMSS,
YYYYMMDD, or YYMMDD.

The CREATE TABLE Statement (DDL)


The CREATE TABLE statement is used to create a table in a database.
SQL CREATE TABLE Syntax
CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....
)

CREATE TABLE Example


Now we want to create a table called "Persons" that contains five columns: P_Id,
LastName, FirstName, Address, and City.
We use the following CREATE TABLE statement:
CREATE TABLE Persons
(
P_Id int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)
The P_Id column is of type int and will hold a number. The LastName, FirstName, Address,
and City columns are of type varchar with a maximum length of 255 characters.
The empty "Persons" table will now look like this:
P_Id LastName FirstName Address City

The empty table can be filled with data with the INSERT INTO statement.

SQL Constraints (Not part of the syllabus)


Constraints are used to limit the type of data that can go into a table. Constraints can be
specified when a table is created (with the CREATE TABLE statement) or after the table
is created (with the ALTER TABLE statement). We will focus on the following constraints:
● NOT NULL
● UNIQUE
● PRIMARY KEY
● FOREIGN KEY
● CHECK
● DEFAULT
SQL PRIMARY KEY Constraint
- The PRIMARY KEY constraint uniquely identifies each record in a database table.
- Primary keys must contain unique values. A primary key column cannot contain NULL
values. - - Each table should have a primary key, and each table can have only one primary
key.
SQL PRIMARY KEY Constraint on CREATE TABLE
The following SQL creates a PRIMARY KEY on the "P_Id" column when the "Persons" table
is created:
Example:
CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
PRIMARY KEY (P_Id)
)

Note: We will use the following table for subsequent queries:


Persons
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

2 Siddiqui Taimur 23 Banjara Hills Surat

3 Prasad Kishan Shonitpuram Srinagar

4 Nilsen Johan Bharat Nagar Srinagar

The INSERT INTO Statement (DML)


The INSERT INTO statement is used to insert a new row in a table.
SQL INSERT INTO Syntax
It is possible to write the INSERT INTO statement in two forms.
The first form doesn't specify the column names where the data will be inserted, only
their values:
INSERT INTO table_name
VALUES (value1, value2, value3,...)
The second form specifies both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
SQL INSERT INTO Example
We have the following "Persons" table:

P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

2 Siddiqui Taimur 23 Banjara Hills Surat

3 Prasad Kishan Shonitpuram Srinagar

Now we want to insert a new row in the "Persons" table.


We use the following SQL statement:
INSERT INTO Persons
VALUES (4,'Nilsen', 'Johan', 'Bharat Nagar', 'Srinagar')
The "Persons" table will now look like this:
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

2 Siddiqui Taimur 23 Banjara Hills Surat

3 Prasad Kishan Shonitpuram Srinagar

4 Nilsen Johan Bharat Nagar Srinagar

Insert Data Only in Specified Columns


It is also possible to only add data in specific columns.
The following SQL statement will add a new row, but only add data in the "P_Id",
"LastName" and the "FirstName" columns:
INSERT INTO Persons (P_Id, LastName, FirstName)
VALUES (5, 'Teja', 'Jaeb')
The "Persons" table will now look like this:
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

2 Siddiqui Taimur 23 Banjara Hills Surat

3 Prasad Kishan Shonitpuram Srinagar

4 Nilsen Johan Bharat Nagar Srinagar


5 Teja Jaeb

SQL SELECT Statement (DQL)


The SELECT statement is used to select data from a database. The result is stored in a
result table, called the result-set.
Syntax:
SELECT column_name(s) FROM table_name;
and
SELECT * FROM table_name;

SQL SELECT Example


SELECT LastName, FirstName FROM Persons;
Output:
LastName FirstName

Halwani Oneer

Siddiqui Taimur

Prasad Kishan

SELECT * Example
Now we want to select all the columns from the "Persons" table. We use the following
SELECT statement:
SELECT * FROM Persons; // The asterisk (*) is a quick way of selecting all columns
Output:
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

2 Siddiqui Taimur 23 Banjara Hills Surat

3 Prasad Kishan Shonitpuram Srinagar

The SQL SELECT DISTINCT Statement


In a table, some of the columns may contain duplicate values. This is not a problem,
however, sometimes you will want to list only the different (distinct) values in a table.
The DISTINCT keyword can be used to return only distinct (different) values.
SQL SELECT DISTINCT Syntax
SELECT DISTINCT
column_name(s)
FROM table_name

SELECT DISTINCT Example


Example:
SELECT DISTINCT City FROM Persons
Output:
City

Surat

Srinagar

The WHERE Clause


The WHERE clause is used to extract only those records that fulfill a specified criterion.
SQL WHERE Syntax
SELECT <column_name(s)>
FROM <table_name>
WHERE <column_name> operator <value>

WHERE Clause Example


The "Persons" table:
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

2 Siddiqui Taimur 23 Banjara Hills Surat

3 Prasad Kishan Shonitpuram Srinagar

Now we want to select only the persons living in the city "Surat" from the table above.We
use the following SELECT statement:
SELECT * FROM Persons
WHERE City='Surat'
The result-set will look like this:
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

2 Siddiqui Taimur 23 Banjara Hills Surat


Quotes Around Text Fields
SQL uses single quotes around text values (most database systems will also accept double
quotes). Although, numeric values should not be enclosed in quotes.

For text values:


This is correct:
SELECT * FROM Persons WHERE FirstName='Taimur'
This is wrong:
SELECT * FROM Persons WHERE FirstName=Taimur
For numeric values:
This is correct:
SELECT * FROM Persons WHERE Year=1965
This is wrong:
SELECT * FROM Persons WHERE Year='1965'

Operators Allowed in the WHERE Clause


With the WHERE clause, the following operators can be used:
Operator Description

= Equal

<> Not equal

> Greater than

< Less than

>= Greater than or equal

<= Less than or equal

BETWEEN Between an inclusive range

LIKE Search for a pattern

IN If you know the exact value you want to return for at least
one of the columns
Note: In some versions of SQL the <> operator may be written as !=

The AND & OR Operators


The AND & OR operators are used to filter records based on more than one condition. The
AND operator displays a record if both the first condition and the second condition is true.
And OR operator displays a record if either the first condition or the second condition is
true.
AND Operator Example

SELECT * FROM Persons


WHERE FirstName='Taimur'
AND LastName='Siddiqui'
The result-set will look like this:
P_Id LastName FirstName Address City

2 Siddiqui Taimur 23 Banjara Hills Surat

OR Operator Example
Now we want to select only the persons with the first name equal to "Taimur" OR the first
name equal to "Oneer":
We use the following SELECT statement:
SELECT * FROM Persons
WHERE FirstName='Taimur'
OR FirstName='Oneer'
The result-set will look like this:
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

2 Siddiqui Taimur 23 Banjara Hills Surat

SQL LIKE Operator


The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
It is used to search for a specified pattern in a column.
SQL LIKE Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern
LIKE Operator Example
SELECT * FROM Persons
WHERE City LIKE 's%'

Pattern (SQL Wildcards)


SQL wildcards can substitute for one or more characters when searching for data in a
database.
SQL wildcards must be used with the SQL LIKE operator. With SQL, the following
wildcards can be used:
Wildcard Description
% A substitute for zero or more characters

_ A substitute for exactly one character

[charlist] Any single character in charlist

[^charlist] Any single character not in charlist


or
[!charlist]

SQL Wildcard Examples

Using the % Wildcard


Now we want to select the persons living in a city that starts with "sa" from the "Persons"
table. We use the following SELECT statement:
SELECT * FROM Persons
WHERE City LIKE 'su%'
The result-set will look like this:
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

2 Siddiqui Taimur 23 Banjara Hills Surat

Next, we want to select the persons living in a city that contains the pattern "nes" from
the "Persons" table. We use the following SELECT statement:
SELECT * FROM Persons
WHERE City LIKE '%rat%'
The result-set will look like this:
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

2 Siddiqui Taimur 23 Banjara Hills Surat

Using the _ Wildcard


Now we want to select the persons with a first name that starts with any character,
followed by "la" from the "Persons" table.
We use the following SELECT statement:
SELECT * FROM Persons
WHERE FirstName LIKE '_neer'
The result-set will look like this:
P_Id LastName FirstName Address City
1 Halwani Oneer Tapovan 10 Surat

Next, we want to select the persons with a last name that starts with "S", followed by any
character, followed by "end", followed by any character, followed by "on" from the
"Persons" table.
We use the following SELECT statement:
SELECT * FROM Persons
WHERE LastName LIKE 'S_dd_ui'
The result-set will look like this:
P_Id LastName FirstName Address City

2 Siddiqui Taimur 23 Banjara Hills Surat

Using the [charlist] Wildcard


We use the following SELECT statement:
SELECT * FROM Persons
WHERE LastName LIKE '[qr]%'
The result-set will look like this:
P_Id LastName FirstName Address City

2 Siddiqui Taimur 23 Banjara Hills Surat

3 Prasad Kishan Shonitpuram Srinagar

We use the following SELECT statement:


SELECT * FROM Persons
WHERE LastName LIKE '[!eqr]%'
The result-set will look like this:
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

The IN Operator
The IN operator allows you to specify multiple values in a WHERE clause.
SQL IN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...)
IN Operator Example
We use the following SELECT statement:
SELECT * FROM Persons
WHERE LastName IN ('Halwani','Prasad')
The result-set will look like this:
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

3 Prasad Kishan Shonitpuram Srinagar

The BETWEEN Operator


The BETWEEN operator selects a range of data between two values. The values can be
numbers, text, or dates.
SQL BETWEEN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2

BETWEEN Operator Example


The "Persons" table:
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

2 Siddiqui Taimur 23 Banjara Hills Surat

3 Prasad Kishan Shonitpuram Srinagar

Now we want to select the persons with a last name alphabetically between "Halwani"
and "Prasad" from the table above.
We use the following SELECT statement:
SELECT * FROM Persons
WHERE LastName
BETWEEN 'Halwani' AND
'Prasad'
The result-set will look like this:
P_Id LastName FirstName Address City

1 Halwani Oneer Tapovan 10 Surat

Note: The BETWEEN operator is treated differently in different databases.


In some databases, persons with the LastName of "Halwani" or "Prasad" will not be listed,
because the BETWEEN operator only selects fields that are between and excluding the
test values).
In other databases, persons with the LastName of "Halwani" or "Prasad" will be listed,
because the BETWEEN operator selects fields that are between and including the test
values).
And in other databases, persons with the LastName of "Halwani" will be listed, but
"Prasad" will not be listed (like the example above), because the BETWEEN operator
selects fields between the test values, including the first test value and excluding the last
test value.
Therefore: Check how your database treats the BETWEEN operator.
Example 2
To display the persons outside the range in the previous example, use NOT BETWEEN:
SELECT * FROM Persons
WHERE LastName
NOT BETWEEN 'Halwani' AND 'Prasad'
The result-set will look like this:
P_Id LastName FirstName Address City

2 Siddiqui Taimur 23 Banjara Hills Surat

3 Prasad Kishan Shonitpuram Srinagar

SQL Alias (Not part of the syllabus)


You can give a table or a column another name by using an alias. This can be a good thing
to do if you have very long or complex table names or column names. An alias name could
be anything, but usually it is short.
SQL Alias Syntax for Columns
SELECT column_name AS alias_name
FROM table_name;
Unit 4: Introduction to the Emerging Trends
Artificial Intelligence, Machine Learning, Natural Language Processing, Immersive
experience (AR, VR), Robotics, Big data and its characteristics, Internet of Things (IoT),
Sensors, Smart cities, Cloud Computing and Cloud Services (SaaS, IaaS, PaaS); Grid
Computing, Block chain technology

4.1 Artificial Intelligence (AI): Artificial intelligence, or I, refers to devices or


programmes that resemble human intelligence in order to carry out tasks and have the
ability to iteratively improve themselves based on the data they gather.
Artificial intelligence aims to imitate human intelligence naturally in machines so
that they will act intelligently. An intelligent machine should be able to mimic some of the
cognitive processes that people use to learn, make decisions, and solve problems.
Machines are trained to build a knowledge base and base judgments off of it in
order to complete jobs with the least amount of human involvement. In order to make
new judgments, AI systems can also learn from their prior actions or results.

4.1.1 Machine Learning: Machine learning is a branch of artificial intelligence


that enables computers to learn from data using statistical methods without
explicit human programming. It includes algorithms that use information to learn
on their own and anticipate the future.

4.1.2 Natural Language Processing (NLP): Natural Language Processing (NLP)


It deals with how people and computers communicate using human spoken
languages like Hindi, English, etc. In fact, using our voice to conduct a web search,
use a device, or control another device is achievable. NLP has made all of this
feasible. An NLP system can convert speech to text and text to speech.

4.2 Immersive Experiences: Now movies are three dimensional, video games are also
being developed to provide immersive experiences to the player. Immersive experiences
allow us to visualize, feel and react by stimulating our senses. It enhances our interaction
and involvement, making them more realistic and engaging. Immersive experiences have
been used in the field of training, such as driving simulators , flight simulators and so on.
● Virtual Reality – Virtual Reality (VR) is a three-dimensional, computer-generated
situation that simulates the real world. The user can interact with and explore that
environment by getting immersed in it while interacting with the objects and
other actions of the user.
● Augmented Reality – The term “augmented reality” refers to the superimposition
of computer-generated perceptual information over the actual physical
surroundings (AR). Consider Pokémon Go as an illustration, where players look
for animated characters that appear in their real-world surroundings on their
phone or tablet.

4.3 Robotics: A robot is essentially a machine that can complete one or more activities
accurately and precisely on its own. A robot is programmable by a computer, which
implies it can obey commands supplied by computer programmes, unlike other devices.
Mars Exploration Rover (MER) is a robotic space mission launched by NASA to
learn more about the planet Mars.Sophia is a humanoid robot that mimics human
movements and facial expressions and uses artificial intelligence, visual data processing,
and facial recognition.
An unmanned aircraft called a drone can be remotely piloted or can fly on its own
using software-controlled flight plans in embedded systems in conjunction with onboard
sensors and GPS.

4.4 Big Data: Every day, over 2.5 quintillion bytes of data are generated, and the rate is
rising due to the Internet of Things’ ongoing development (IoT). As a result, big data, data
sets with a large volume and high level of complexity are created.
Such data cannot be handled and analyzed using conventional data processing
methods because it is not only large but also unstructured, such as our posts,
conversations, and instant messages, as well as the pictures.
This data is highly valuable in the businesses, So, there is a strong focus on
developing tools and processes to process and analyze big data.

Characteristics of Big DataThere are five different types of characteristics of Big Data –
1. Volume – Size presents the biggest challenge for large data. It will be challenging
to process a certain dataset if it is large.
2. Velocity – Velocity is the term used to describe the speed with which information
must be processed after being input into a system. For example, Amazon record
every click of the mouse when the shoppers are browsing on its website.
3. Variety – All the organized and unstructured data that could be produced by
either people or machines is referred to as variety in big data.
4. Veracity – Big data can occasionally be inaccurate, distorted, noisy, or contain
errors. It can also have problems with the methods used to obtain the data.
Veracity relates to how reliable the data is.
5. Value – Big data is more than just a large collection of data; it also contains hidden
patterns and insightful information that may be highly valuable to businesses.

4.5 Data Analytics: The practice of analysing datasets to make judgments about the
information they contain is known as data analytics. You can take raw data and use data
analytical tools to find patterns and gain insightful conclusions from it.
“Data analytics is the process of examining data sets in order to draw conclusions
about the information they contain, with the aid of specialised systems and software.

4.6 ”Internet of Things (IoT) The “Internet of Things” is a collection of interconnected


devices that can connect to one another and exchange data in the same network or you
can say, It is an overall network of interconnected devices as well as the technology that
enables communication between them.

4.7 Web of Things (WoT) Internet of Things allows us to interact with different devices
through the Internet with the help of smartphones or computers, Web of Things (WoT)
allows use of web services to connect anything in the physical world, besides human
identities on the web. It will pave the way for creating smart homes, smart offices, smart
cities and so on.
4.8 Sensors: Sensors are frequently used as monitoring and observing components. The
development of IoT is being greatly aided by the evolution of smart electronic sensors. It
will result in the development of fresh, intelligent systems with sensors.
A smart sensor is a device that receives input from the physical world and uses
internal computer power to carry out predetermined tasks when a certain input is
detected. The data is then processed before being transmitted.Smart CitiesA smart city
use the information and communication technologies (ICT), for creating, implementing,
and promoting sustainable development methods to handle the issues of expanding
urbanisation.

4.9 Smart City: handle transportation systems, power plants, water supply networks,
waste management, law enforcement, information systems, schools, libraries, hospitals
and other community services work in unison to optimise the efficiency of city operations
and services through the information and communication technologies.

4.10 Cloud Computing: Cloud computing is a new trend where computer-based services
are supplied via the Internet or the cloud and are accessible to the user from any location
using any device.
Cloud computing is the distribution of computer services over the Internet (“the
cloud”), including servers, storage, databases, networking, software, analytics, and
intelligence.Cloud Services.
There are three standard models to categorise different computing services delivered
through the cloud.
1. Infrastructure as a Service (IaaS)
2. Platform as a Service (PaaS)
3. Software as a Service (SaaS)
1. Infrastructure as a Service (IaaS) – IaaS is a particular kind of cloud
computing service that provides necessary computation, storage, and networking
resources on demand for example different types of computer infrastructure, such
as servers, virtual machines (VM), storage and backup facilities, network
components, operating systems, or any other hardware or software, can be offered
by IaaS providers.

2. Platform as a Service (PaaS) – a cloud-based service that enables users to


install and run applications without worrying about their setup or underlying
infrastructure. In other words, PaaS offers a platform or setting for creating,
testing, and distributing software applications.

3. Software as a Service (SaaS) – SaaS offers on-demand access to application


software; often, this service requires user licencing or subscription. We utilise
SaaS from the cloud when using Google Doc, Microsoft Office 365, Drop Box, etc.
to modify a document online.

4.11 Grid Computing: Grid computing refers to a network of computers from various
administrative domains cooperating to complete a task. Grid computing enables simple
completion of complicated tasks that may be intractable for a single computer machine.
Grid can be of two types:
1. Data grid: used to manage large and distributed data having required multi-user
access
2. CPU or Processor grid: where processing is moved from one PC to another as
needed or a large task is divided into subtasks and divided to various nodes for
parallel processing.

4.12 Blockchains: The blockchain technology is based on the idea of a shared,


decentralised database that is replicated on every computer. A block is a safeguarded
section of data or a legitimate transaction. Only the block’s owner has access to the block’s
private data, which is hidden behind the header of each block, which is visible to all other
nodes. These blocks come together to form the blockchain.

Image via NCERT

You might also like