3. Unit I: Computational Thinking and
Programming- 2
● Revision of the basics of Python covered in Class XI.
● Functions: scope, parameter passing, mutable/immutable properties of
data objects, passing strings, lists, tuples, dictionaries to functions, default
parameters, positional parameters, return values, functions using libraries:
mathematical and string functions.
● File handling: Need for a data file, Types of file: Text files, Binary files and
CSV (Comma separated values) files.
4. Text File: Basic operations on a text file: Open (filename – absolute or
relative path, mode) / Close a text file, Reading and Manipulation of
data from a text file, Appending data into a text file, standard input /
output and error streams, relative and absolute paths.
● Binary File: Basic operations on a binary file: Open (filename –
absolute or relative path, mode) / Close a binary file, Pickle Module –
methods load and dump; Read, Write/Create, Search, Append and
Update operations in a binary file.
CSV File: Import csv module, functions – Open / Close a csv file, Read
from a csv file and Write into a csv file using csv.reader ( ) and
csv.writerow( ).
5. • Using Python libraries: create and import
Python libraries.
• Data-structures: Lists as covered in Class XI, Stacks
– Push, Pop using a list, Queues – Insert, Delete using
a list.
6. Unit III: Database Management
Database Concepts: Introduction to database concepts and its need.
Relational data model: Concept of domain, relation, tuple, attribute, degree,
cardinality, key, primary key, candidate key, alternate key and foreign key;
Structured Query Language:
General Concepts: Advantages of using SQL, Data Definition Language and
Data Manipulation Language;
Data Types: number / decimal, character / varchar / varchar2, date;
SQL commands: CREATE TABLE, DROP TABLE, ALTER TABLE, UPDATE
....SET...., INSERT, DELETE; SELECT, DISTINCT, FROM, WHERE, IN,
BETWEEN, LIKE, NULL / IS NULL, ORDER BY,GROUP BY, HAVING;
SQL functions: SUM ( ), AVG ( ), COUNT ( ), MAX ( ) and MIN ( );
Joins: equi-join and natural join
7. - Connecting SQL with Python
- Creating Database connectivity Applications
- Performing Insert, Update, Delete queries
- Display data by using
fetchone(),fetchall(),rowcount
Interface of Python with an SQL database
8. ● Evolution of Networking: ARPANET, Internet, Interspace Different ways of sending data across
the network with reference to switching techniques (Circuit and Packet switching).
● Data Communication terminologies: Concept of Channel, Bandwidth (Hz, KHz, MHz) and Data
transfer rate (bps, Kbps, Mbps, Gbps, Tbps).
● Transmission media: Twisted pair cable, coaxial cable, optical fiber, infrared, radio link,
microwave link and satellite link.
● Network devices: Modem, RJ45 connector, Ethernet Card, Router, Switch, Gateway, WiFi card.
● Network Topologies and types: Bus, Star, Tree, PAN, LAN, WAN, MAN.
● Network Protocol: TCP/IP, File Transfer Protocol (FTP), PPP, HTTP, SMTP, POP3, Remote Login
(Telnet) and Internet, Wireless / Mobile Communication protocol such as GSM, GPRS and WLL.
● Mobile Telecommunication Technologies: 1G, 2G, 3G, 4G and 5G; Mobile processors; Electronic
mail protocols such as SMTP, POP3, Protocols for Chat and Video Conferencing: VoIP, Wireless
technologies such as Wi-Fi and WiMax Network Security Concepts: Threats and prevention from
Viruses, Worms, Trojan horse, Spams Use of Cookies, Protection using Firewall, https; India IT Act,
Cyber Law, Cyber Crimes, IPR issues, hacking.
● Introduction To Web services: WWW, Hyper Text Markup Language (HTML), Extensible Markup
Language (XML); Hyper Text Transfer Protocol (HTTP); Domain Names; URL; Website, Web browser,
Web 8 Servers; Web Hosting.
Unit II: Computer Network
14. Terms
? What are the advantages of database systems?
ANS SECURITY, PRIVACY(requires password),REDUCING
REDUNDANCY(not required to write students name multiple times for
different categories),AVOIDING INCONSISTENCY,DATA
INTEGRITY(database has a universal standard form
everywhere)SPEED(easy to check things fast)
? Give examples for : relation, domain, tuple, RDBMS, Domain, Attribute,
Degree, Cardinality, using a table.
15. Keys
? Primary : column/s used for unique
identification of each tuple
? Candidate: All attributes or combinations
which can serve as Primary key
? Alternate: Any candidate key which is not
chosen to be a Primary Key
? Foreign Key : A Primary key derived
from a different table, with values
18. Referential Integrity
? Rules to protect relation among records of tables,
during removal or modification.
? Conditions to be met:
? Parent table: Primary Key/ Unique
? Foreign key: same datatype as primary key
? Same database for both tables
19. Referential Integrity - Don’ts
? New values not allowed in foreign key, null allowed
?Cannot delete a record from parent table if value
exists in foreign key
delete from parent_table where Pri_key = v1;
delete from parent_table where Pri_key = v2;
? Cannot edit primary key, if it has matching records in
child table.
update parent_table set Pri_key = v4 where Pri_key = v1;
update parent_table set Pri_key = v4 where Pri_key = v3;
For_Key Col
1
Col
2
Existing
New
Pri_Key Col 1 Col 2
v1
v2
For_Ke
y
Col 1 Col 2
v1
v3
20. MySql , SQL
MySQL
A software/ RDBMS that uses SQL
Open Source
SQL – Structured Query Language
Language to use a database
Variance in commands across platforms
24. DDL (Data Definition Language) – It allows you to
perform various operations on the database such as
CREATE, ALTER and DROP objects.
DML (Data Manipulation Language) – It allows you to
access and manipulate data. It helps you to insert,
update, delete and retrieve data from the database.
DCL (Data Control Language) – It allows you to control
access to the database. Example – Grant or Revoke
access permissions.
TCL (Transaction Control Language) – It allows you to
deal with the transaction of the database. Example –
Commit, Rollback, Savepoint, Set Transaction.
25. QUESTIONS
? Identify the category to perform the following tasks:
? A) change a column’s width
? B) change a column’s data type
? C) add a new column
? D) remove a table
? E) remove only data from a table , but retain the column headers,
structure
? F) replace data with new data
? G) add a new row of data / tuple
? H) remove the user accessibility to a set of tables.
27. MySql client
• Click open MySql command line client
• Enter password
• Type the following command to start working:
• Use test;
• Test is the name of the database
• You can also make a database:
• Create database new;
28. Formats
• Use semicolon at the end of each statement.
• SQL is NOT case sensitive but is DATA SENSITIVE
• Use : https://www.db-fiddle.com/ or
http://sqlfiddle.com/, temporarily
29. Data types
? Varchar versus char
? First_name: varchar(10) , Last_name : char(10)
Bytes for First_name Bytes for last_name
6 10 (King_ _ _ _ _ _)
5 10(Kochhar_ _ _)
3 10(De Haan_ _ _)
30. Other data types
? integer or int
? float
? date – format for storing date values: yyyy-mm-dd
? You can use built in functions to convert a string to date
form
31. Command, clause
• SQL commands are the instructions used to
communicate with a database to perform tasks,
functions, and queries with data.
• Clauses are subsets of commands that modify the
command.
32. Commands, clauses
1. Create table (with constraints)
2. desc
3. Insert into….values, insert into t1(select * from t2)
4. Select – simple
5. Order by – single column, multiple cols
6. Where : relational operators, in , between, like (%, _), is, is
not, logical operators
7. Update…set…where
8. Delete from…where
9. Alter table…add…modify….change…..drop column
10. Drop table
33. 1. Create table
Command used to make a table structure with column headers
• CREATE TABLE [IF NOT EXISTS] table_name (
column1 datatype [constraint / key],
column2 datatype,
column3 datatype,
last column,
table level constraint 1,
table level constraint 2,
…
);
Example: create table emp(
empcode int(5) PRIMARY KEY, name varchar(15), doj date, sal
float(6,2) );
Table level:
create table emp(
empcode int(5) , name varchar(15), doj date, sal float(6,2),
primary key(empcode));
34. 2. desc
Command that displays structure of the table , with
column description, basic constraints, null options, default
values
• Desc table;
• Or
• Describe table;
Example:
Desc emp;
35. 3. Insert into…values()
• Used to add data into a table , using values clause
• insert into t1(select * from t2)
• Insert into table_name (col1,col2,col3..)
• Values(v1,v2,v3…);
• Example:
Insert into emp( empcode , name, doj , sal)
Values( 101, 'abc', '2021-02-01', 30000);
Date value is entered in the format: ‘yyyy-mm-dd’
Strings are entered in single quotes only - Do not
use double quotes
Blank value is indicated by typing NULL
37. 4. Select – simple form
• Displays values of the columns specified in the statement.
Result table has the column names specified in the query,
using from clause.
• Select col1, col2, col3… from table;
• Or
• Select * from table; (to display all columns)
• Example:
• Select empcode , name from emp;
• Select * from emp;
38. 5. Order by – single column,
multiple cols
• This clause works with select command to display values
in ascending / descending order of the chosen column.
• Default order: ascending
• Select col1, col2…from table order by col2 [desc];
• Example:
• Select name,sal order by doj;
• Table is ordered in increasing order of doj, from where
name and sal values are displayed.
• Multiple columns:
• Select name,sal order by name,doj;
• Arranges all names in ascending order, followed by
dates, for repeated values.
40. Where : relational operators
• All operators same as in python , except ==
• Use = for equality comparison in sql
• All operators work on all three data types: numeric,
varchar, date
• Example:
• Select name from emp where sal>25000;
• Select name from emp where name>’Alex’;
• Select name from emp where doj> ‘2020-01-01’;
All operators work
on all data types
41. Where: Logical operators
• And, or , not
• Same as in python
• Work on all data types
• Select empcode from emp where not( sal>20000 and
sal<30000);
• Select name from emp where empcode=101 or
name=‘Richa’;
42. Where: in , between
• In operator can be used to match against multiple values
for the same column.
• Example:
• Select name from emp where empcode in(101,201);
• Between works to select values in a range, both values
inclusive; Example:
• Select name from emp where sal between 20000 and
50000;
43. Where : like (%, _)
• Used for pattern matching: starts with letter ‘A’, in the
month of jan, etc
• % and _ are wild card characters. They are used to
substitute unknown characters.
• % represents many characters
• _ represents one
• Example:
• Select name from emp where name like ‘A%’;
• Select doj from emp where doj like ‘%jan%’;
44. Where: is, is not
• Is operator works with null value only
• It can be combined with not operator
• Example :
• Select name from emp where doj is null;
• Select name from emp where sal is not null;
47. Update…set
The command is used to replace/edit data .
Update <table> set <col> = <value> [where clause]
The command changes all values of a column, if where clause is not used.
Example:
Update emp set empcode=201;
-changes all values under the column empcode to 201
Update emp set empcode=201 where name= ‘Yash’;
-changes value of all tuples containing the name yash
47
48. Delete from…where
• The command removes tuple/s from a table
• If used without where clause, removes all tuples.
• Delete from <table> [where clause]
• Example
• Delete from emp where empcode=101;
• Removes all rows with the given code
• Delete from emp;
• Removes all rows
48
9/3/20XX
PRESENTATION TITLE
51. Drop table
Removes a table along with all content/data
• Drop table <tablename>
• Drop table emp;
To remove particular column:
alter table emp
drop ename;
52. Alter table
Clauses
• Add
• Modify
• Change
• Drop column
Description
• Add a new column.
• Change column type or width.
• Change column name or position
• Remove a column
• Alter table <table name>add <column definition>;
• Alter table <table name> modify <column definition>;
• Alter table <table name> change [COLUMN] old_col_name new_col_name
column_definition [FIRST | AFTER col_name]
• Alter table <table name> DROP [COLUMN] col_name
53. Examples
• Alter table emp add
( email varchar(15) );
Alter table emp add email
varchar(20) FIRST;
Alter table emp add email
varchar(20) AFTER sal;
• Alter table emp modify
( name varchar(25)) ;
• Alter table emp change
name empname varchar(15) FIRST ;
• Alter table emp change empcode ecode
int after sal;
• Alter table emp DROP sal;
55. ALTER TABLE table_name ADD CONSTRAINT MyPrimaryKey PRIMARY KEY (column1,
column2...);
alter table student
add constraint primary key(rollno);
alter table student
-> add constraint check(dob>'2000-09-09');
alter table emp
add constraint c1 check (deptno>5);
alter table student
-> drop primary key;
alter table emp
drop primary key MyPrimaryKey;
alter table emp
drop constraint c1;
56. alter table student
alter marks set default 30;
alter table student
alter marks drop default;
alter table club
alter clubname drop default;
alter table club
modify clubname varchar(30) not null;
alter table club
modify clubname varchar(30);
56
59. Joins
✔Cartesian Product – no condition, each value of T1with each value
of T2
✔Equi join – where cluase with = operator
✔Natural Join – same as equi, but common column chosen by DBMS
https://www.youtube.com/watch?v=bLL5NbBEg2I
https://dataschool.com/how-to-teach-people-sql/inner-join-
animated/
63. Aggregate/ group functions
1. SUM ( ) – only numeric
columns
2. AVG ( ) - only numeric
columns
3. COUNT ( ) – any type
4. MAX ( ) – any type
5. MIN ( ) – any type
6. Distinct or all can be used
7. * can be used only with count
– indicates to include null.
71. Position - All clauses
1. From (single /
multiple tables)
2. Where
3. Group by
4. Having
5. Order by
? Without /with join
? Select required rows
? Merge rows, create
groups
? Select groups using
group functions
? Arrange the result of
the above