Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 38

Practical File(2024-2025)

Index
Program No Title
Program-1 Basics of Python-Phishing E-Mail
Program-2 Functions- Printing Factorial/Fibonacci/Prime Number
Program-3 Built in Module-Using Statistics/Random module
Program-4 Text File-1- Manipulating lines
Program-5 Text File-2 -Analysing characters
Program-6 Text File-3 – Manipulating words
Program-7 Binary File-1 – Inserting, Displaying and Searching with list
Program-8 Binary File-2 - Inserting, Displaying and Deleting with list
Program-9 Binary File-3 - Inserting, Displaying and Updating with Dictionary
Program-10 CSV File-1 – Inserting, Displaying and Updating with list
Program-11 CSV File-2 - Inserting, Deleting and displaying with list
Program-12 CSV File-3 - Inserting, Searching and Displaying with List
Program-13 Stack-1-Push, Pop and Display with list
Program-14 Stack-2-Push and Peek with list
Program-15 Stack-3- Push, count of stk_ele and Display with dictionary
Program-16 SQL Queries – 1 - Carden & Model Table
Program-17 SQL Queries – 2 - Sports Table
Program-18 SQL Queries – 3 - Myorder & Mystatus Table
Program-19 SQL Queries – 4 - Students Table
Program-20 SQL Queries – 5 - Employee Table
Program-21 SQL Queries – 6 - Item Table
Program-22 SQL Queries – 7 – Worker Table
Program-23 SQL Queries – 8 - Personal & Job Table
Program-24 SQL Queries – 9 - Books Table
Program-25 SQL Queries – 10 – Collections Table
Program-26 PYTHON-SQL CONNECTIVITY-1-Table creation and record insertion
Program-27 PYTHON-SQL CONNECTIVITY-2- Record updating
Program-28 PYTHON-SQL CONNECTIVITY-3- Record deletion
Program-29 PYTHON-SQL CONNECTIVITY-4- Search and Display
Program-30 PYTHON-SQL CONNECTIVITY-5- Database creation ,Table creation and
Table alteration
Class XII - Computer Science with Python(083)

Note:
Write the Title, Question, Aim , Code and Result on the R.H.S.(with blue ink) of your
observation notebook & record note book, the output alone on the L.H.S.(will be given
later).Open the link of Python program in laptop or desktop to see the code.
Start every exercise on a fresh page

Program 1:
Title: Basics of Python-Phishing E-Mail
Question: Write a Program to take 10 sample phishing emails and find the most common
occurring domain.
AIM: To write a Program to take 10 sample phishing emails and find the most common
occurring domain.
CODE:
https://drive.google.com/file/d/1u0lcPxuHzW5spMlcLSkKaBx8iCXXBj2z/view?usp=share_link
Result: The above program is executed successfully and the output is verified
Program 2:
Title: Functions- Printing Factorial/Fibonacci/Prime Number
Question: Write a program to calculate the factorial value or to print the Fibonacci series
for n terms or check whether the entered no. is prime or not based on users’ choice.
AIM:
To write a menu driven program
1. to calculate the factorial value
2. to print the Fibonacci series for n terms
3. to check whether the entered no. is prime or not.

CODE: https://drive.google.com/file/d/1RKBVdA1fstjSQlhb2um5UkGbhzezPFWY/view?
usp=share_link

Result: The above program is executed successfully and the output is verified
Program:3
Title: Built in Module-Using Statistics/Random module
Question: Write a Program to use the functions from Statistics and Random modules.
Aim: To write a menu – driven program to import and use the below modules.
1.Statistics
2.Random
CODE:
https://drive.google.com/file/d/1vfR7DkXCG9-g9hP3SlPHdUiCYlffNDXP/view?usp=share_link

Result: The above program is executed successfully and the output is verified
Program 4 :
Title: Text File-1- Manipulating lines
Question: Write a text file handling program in python to do the following
1. To read a text file line by line and display each word separated by a #.
2. To remove all the lines that contain the character `W’ from a file and write it to another
file

AIM: To write a menu – driven program to perform the following on a text file
1. To write a python function to read a text file line by line and display each word
separated by a #.
2. To write a python function to remove all the lines that contain the character `W’
from a file and write it to another file
CODE:
https://drive.google.com/file/d/16Yr-e-l8_785RP6rlcpSl9hzAFlkfQTE/view?usp=share_link

Result: The above program is executed successfully and the output is verified
Program 5:
Title : Text File-2 -Analysing characters
Question: Write a text file handling program in python to do the following
1. Display the number of vowels
2. Display the number of consonants
3. Display the number of upper-case characters
4. Display the number of lower-case characters

AIM:
To write a menu – driven program to perform the following on a text file
1. Display the number of vowels
2. Display the number of consonants
3. Display the number of upper-case characters
4. Display the number of lower-case characters
CODE:
https://drive.google.com/file/d/1TPPNBwqYgQO5HBqLfl6LsQzoy6nLsHDN/view?usp=share_link

Result: The above program is executed successfully and the output is verified
Program 6:
Title: Text File-3 – Manipulating words
Question: Write a text file handling program in python to do the following
1. Counting the specific word in a file
2. Replace the given word with another word
3. Display the words ending with character 'e'
4. Display the longest word of the file

AIM:
To write a menu – driven program to perform the following on a text file
1. Counting the specific word in a file
2. Display the text after replacing the given word with another word
3. Display the words ending with character 'e'
4. Display the longest word of the file
CODE:
https://drive.google.com/file/d/18RF9KkhkCVzGRLuB2qyiEkI2LYjzS1_q/view?usp=share_link

Result: The above program is executed successfully and the output is verified
Program 7:
Title: Binary File-1 – Inserting, Displaying and Searching with list
Question: Write a Program to create a product record on a binary file.
AIM: To write a python
1.Insert record
2.Display record
3.Search record
4.Exit
CODE:
https://drive.google.com/file/d/1ZMM3S_5Y1AF5xNpt_io_I_Bu96hxsqil/view?usp=share_link

Result: The above program is executed successfully and the output is verified
Program 8:
Title : Binary File-2 - Inserting, Displaying and Deleting with list
Question: Write a Program to Create an Employee Record on a Binary File.
AIM:
To write a menu – driven program to perform the following tasks on a Binary file
1.Insert record
2.Display record
3.Delete record
4.Exit
CODE:
https://drive.google.com/file/d/1mCEZhqjz9I28ZuHCWP2Q2pIZsyvPz-X2/view?usp=share_link

Result: The above program is executed successfully and the output is verified
Program 9:
Title : Binary File-3 - Inserting, Displaying and Updating with Dictionary
Question: Write a Program to Create a Student Record on a Binary File.
AIM:
To write a menu – driven program to perform the following tasks on a Binary file
1.Enter data
2.Display data
3.Update data
4.Exit
CODE:
https://drive.google.com/file/d/1d5K2-3nmhmfxGZPA7nPFsznLMlwLHf-W/view?usp=share_link

Result: The above program is executed successfully and the output is verified
Program -10:
Title : CSV File-1 – Inserting, Displaying and Updating with list
Question: Write a Program to Create a Customer record with CSV file.
AIM:
To write a menu – driven program to perform the following tasks on a CSV file
1-Add record
2-Display records
3-Modify record
4-Exit
CODE:
https://drive.google.com/file/d/16m2LVWzE5ydfAKq-dzjFkJ0S2UN_LFlo/view?usp=share_link

Result: The above program is executed successfully and the output is verified
Program -11:
Title : CSV File-2 - Inserting, Deleting and displaying with list

Question: Write a Program to Create a Book Details Record using CSV file.
AIM:
To write a menu – driven program to perform the following tasks on a CSV file
1. Add New Book
2. Display Books in sorted order
3. Delete Book
4. Quit
CODE:
https://drive.google.com/file/d/1mX-9jgIN5u46OhARZKEjtyRX0ElFV-i_/view?usp=share_link

Result: The above program is executed successfully and the output is verified
Program -12:
Title : CSV File-3 - Inserting, Searching and Displaying with List

Question: Write a Program to Create a record of user credentials using CSV file.
AIM:
To write a menu – driven program to perform the following tasks on a CSV file
1: Create
2: Search
3: Display
4: Exit
CODE:
https://drive.google.com/file/d/1E2AKA0kH28ArcKh5ef6rZF6QLFTo5bfl/view?usp=share_link

Result: The above program is executed successfully and the output is verified
Program -13:
Title : Stack-1-Push, Pop and Display with list
Question: Write a Program to Create and perform all basic operations of Stack with list of
numbers
AIM:
To write a menu – driven program to perform the following tasks on a number Stack.
STACK OPERATIONS
1: PUSH the elements divisible by 5
2: POP
3: Display
4: Exit
CODE:
https://drive.google.com/file/d/1IRP-pyVPEgyoYWFd5GNxBDCQNqjTNpSr/view?usp=drive_link

Result: The above program is executed successfully and the output is verified
Program -14:
Title : Stack-2-Push and Peek with list
Question: Write a Program to Create and perform all basic operations of Stack with
customer details
AIM:
To write a menu – driven program to perform the following tasks on a
Customer[Customer_name, Phone_number, City] Stack
1: PUSH - The customer details based on city
2: PEEK
3: EXIT
CODE:
https://drive.google.com/file/d/1D5PNGSHzTJ8j6sn2Wmx4dR6IZbcKqzq5/view?usp=share_link

Result: The above program is executed successfully and the output is verified
Program -15:
Title : Stack-3- Push, count of stk_ele and Display with dictionary
Question: Write a Program to Create and perform all basic operations of Stack with
dictionary {pname:price}
AIM:
To write a menu – driven program to perform the following tasks on a product Stack
STACK OPERATIONS
1: PUSH Product names with price > 75
2: Count the no. of elements in stack
3: Display
4: Exit
CODE:
https://drive.google.com/file/d/1zpQ197lynswzZmiyUW2VmohYuWSuP_fc/view?usp=share_link

Result: The above program is executed successfully and the output is verified
Program 16
Title: SQL Queries – 1 - Carden & Model Table
Question: Write SQL queries to perform the following task on PRACTICALS”
database with the given Table(s).
Aim:
To create the following table(s) and insert records
To execute the following queries on the created table(s)
Table : CARDEN
Ccode CarName Color Capacity Charges
501 A-Star RED 3 14
503 Indica SILVER 3 12
502 Innova WHITE 7 15
509 SX4 SILVER 4 14
510 C Class RED 4 35
Table :MODEL

CarName Year Manufacturer


A-Star 2001 Suzuki
XUV300 2012 Mahindra
Indica 2003 Tata
Innova 2010 Toyota
SX4 2007 Suzuki
Altroz 2020 Tata
C Class 2010 Mercedes

i) To display the names of all the silver-colored Cars


SELECT CARNAME FROM CARDEN WHERE COLOR=”SILVER”;
ii) To increase charges by 10 where capacity is greater than 3
UPDATE CRDERN SET CHARGES = CHARGES + 10 WHERE CAPACITY > 3 ;
iii) To display the Ccode, CarName and Manufacturer.
SELECT CCODE, MODEL.CARNAME, MANUFACTURER FROM
CARDEN,MODEL WHERE MODEL.CARNAME=CARDEN.CARNAME;
iv) To display the cars released in the year 2010.
SELECT CARNAME,YEAR FROM MODEL WHERE YEAR=2010;
Result: The above tables are created, records have been inserted, queries are
executed and outputs are verified successfully
Program 17

Title:SQL Queries – 2 - Sports Table


Question: Write SQL queries to perform the following task on “PRACTICALS”
database with the given Table(s).
Aim:
To create the following table(s) and insert records
To execute the following queries on the created table(s)

Tabe: SPORTS

Stud_no Std name game grade


10 7 Sameer Cricket B
11 8 Sujith Tennis A
12 7 Kamal Swimming B
13 7 Venna Tennis C
14 9 Archana Basketball A
15 10 Arpit Cricket A
i)To display the name of students with game as swimming
SELECT NAME FROM SPORTS WHERE GAME LIKE “SWIMMING”;

ii)To delete the rows where Std is 10


DELETE FROM SPORTS WHERE STD=10;

iii)To display the number of students from each Std.


SELECT COUNT(*) , STD FROM SPORTS GROUP BY STD;

iv)To display the name of the students in ascending order


SELECT NAME FROM SPORTS ORDER BY NAME;

Result: The above tables are created, records have been inserted, queries are
executed and outputs are verified successfully
Program 18
Title: SQL Queries – 3 - Myorder & Mystatus Table
Question: Write SQL queries to perform the following task on “PRACTICALS” database
with the given Table(s).
Aim:
To create the following table(s) and insert records
To execute the following queries on the created table(s)
Table: MYORDER
OrderID Pname Quantity Rate Sale_date Discount
1001 Pen 10 20 2019-10-05 Null
1002 Pencil 20 10 2019-10-21 Null
1003 Book 10 100 2019-11-12 50
1004 Eraser 100 5 2019-12-05 25
1005 Ruler 50 25 2019-12-10 Null
Table:MYSTATUS
OrderI Status
D
1001 Booked
1002 Despatche
d
1007 Pending
1004 Despatche
d
(i)To display Pname, 1005 Despatche Quantity and Rate for all the
orders that are either pen d or pencil
SELECT 1006 Despatche PNAME,QUANTITY,RATE
FROM MYORDER d WHERE PNAME IN
(‘PEN’,’PENCIL’);
(ii)To display orders which are not getting any discount
SELECT * FROM MYORDER WHERE DISCOUNT IS NULL;
(iii)To display OrderID, Sale_date, Status.
SELECT MYORDER.ORDERID, SALE_DATE, STATUS FROM
MYORDER,MYSTATUS WHERE MYORDER.ORDERID = MYSTATUS.ORDERID;
(iv) To display the order details of the product whose rate is more than 20
SELECT * FROM MYORDER WHERE RATE>20;

Result: The above tables are created, records have been inserted, queries are executed
and outputs are verified successfully
Program 19
Title: SQL Queries – 4 – Students Table
Question:Write SQL queries to perform the following task on “PRACTICALS” database
with the given Table(s).
Aim:
To create the following table(s) and insert records
To execute the following queries on the created table(s)
Table: “STUDENTS”

i)To display the records from table students in alphabetical order as per the name of the student.
SELECT * FROM STUDENTS ORDER BY NAME;
ii)To display Class, DOB and City whose marks is between 450 and 551
SELECT CLASS, DOB, CITY FROM STUDENTS WHERE MARKS BETWEEN 450
AND 551;
iii)To display the highest marks and lowest marks of class-XII students
SELECT MAX(MARKS) , MIN(MARKS) FROM STUDENTS WHERE
CLASS=”XII”;
iv)To display the name and gender of the student those who are born in the year 1995
SELECT NAME, GENDER FROM STUDENTS WHERE YEAR(DOB)=1995;

Result: The above tables are created, records have been inserted, queries are executed and
outputs are verified successfully
Program 20
Title: SQL Queries – 5 – Employee Table
Question:
Write SQL queries to perform the following task on “PRACTICALS” database with
the given Table.
Aim:
To create the following table(s) and insert records
To execute the following queries on the created table(s)

Table :“EMPLOYEE”

Ecode Ename Sex Salary Subject JoinDate


F1001 Hari Charan M 101000 English 2000-10-11
F1004 Mallika F 202000 Programming 2003-11-30
F1002 Arun M 202000 Web design 2001-09-06
F1005 Priya F 201000 Web design 2004-12-15
F1009 Tanya F 203000 Programming 2006-12-31
F1006 Amar M 108000 Data structure 2005-05-02
F1008 Avinash M 105000 Maths 2002-03-15

i) To display Ecode, Ename, JoinDate, Salary of all faculty members in descending order of
their salary.
SELECT ECODE, ENAME, JOINDATE, SALARY FROM EMPLOYEE ORDER BY
SALARY DESC;
ii) To increase the salary of all faculties by 2000, who are either teaching the subject
“Programming” or teaching the subject “Maths”.
UPDATE EMPLOYEE SET SALARY = SALARY + 2000 WHERE SUBJECT IN
(‘PROGRAMMING’,’MATHS’)
iii) To display details of all faculty whose name ends with letter “n”.
SELECT * FROM EMPLOYEE WHERE ENAME LIKE “%N”;
iv)To count the employees gender wise.
SELECT COUNT(*),SEX FROM EMPLOYEE GROUP BY SEX;

Result: The above tables are created, records have been inserted, queries are executed
and outputs are verified successfully
Program 21

Title: SQL Queries – 6 - ITEM Table


Question:
Write SQL queries to perform the following task on “PRACTICALS”
database with the given Table(s).
Aim:
To create the following table(s) and insert records
To execute the following queries on the created table(s)

Table:ITEM

ItemNo Name Dcode Qty UnitPrice StockDate


5005 CD 101 100 25 2010-03-31
5003 Floppy 101 150 10 2010-01-01
5002 Pendrive 101 125 200 2010-02-14
5006 Mouse 102 200 300 2009-03-19
5001 Keyboard 102 60 400 2009-12-19

i)To display the Item name with stockdate in the year 2010.
SELECT NAME, STOCKDATE FROM ITEM WHERE YEAR(STOCKDATE)=2010;
ii) To display the ItemNo and name of those items whose Unitprice is more than Rs10.
SELECT ITEMNO, NAME FROM ITEM WHERE UNITPRICE > 10;
iii) To display the total Qty of each Dcode.
SELECT SUM(QTY) , DCODE FROM ITEM GROUP BY DCODE;
iv) To change the unit price of CD to 30.
UPDATE ITEM SET UNITPRICE=30 WHERE NAME=”CD”;

Result: The above tables are created, records have been inserted, queries are executed
and outputs are verified successfully
Program 22

Title: SQL Queries 7 – WORKER Table


Question:
Write SQL queries to perform the following task on “PRACTICALS”
database with the given Table(s).
Aim:
To create the following table(s) and insert records
To execute the following queries on the created table(s)

Table : WORKER
WNO NAME DOJ DOB GENDER DCODE
101 Guru 2013-09-02 1991-09-01 MALE D001
102 Ramya 2012-12-11 1990-12-15 FEMALE D003
104 Manila 2012-12-09 1986-11-14 FEMALE D001
105 Sanjay Roy 2013-11-18 1987-03-31 MALE D002
106 Jaya 2014-06-09 1985-06-23 FEMALE D005

(i) To display WNO, Name, Gender in descending order of NAME.


SELECT WNO, NAME, GENDER FROM WORKER ORDER BY NAME DESC;

(ii) To display the DCODE,NAME of all the MALE workers.


SELECT DCODE,NAME FROM WORKER WHERE GENDER=”MALE”;

(iii) To display the WNO and Name of those workers who are born between ‘1988-01-01’ and
‘1992-12-01’.
SELECT WNO, NAME FROM WORKER WHERE DOB BETWEEN ‘1988-01-01’ AND ‘1992-12-01’;

(iv) To count and display Male workers who have joined after ‘1986-01-01’.
SELECT COUNT(*) FROM WORKER WHERE GENDER=”MALE” AND DOJ > ‘1986-01-01’;

Result: The above tables are created, records have been inserted, queries are executed
and outputs are verified successfully
Program 23

Title: SQL Queries-8 - PERSONAL, JOB Tables


Question:
Write SQL queries to perform the following task on “PRACTICALS” database with
the given Table(s).
Aim:
To create the following table(s) and insert records
To execute the following queries on the created table(s)
Table: Personal

Empno Name Dobirth Native_place Hobby

123 Amudha 23-Jan-1965 Delhi Singing

127 Manoj 12-dec-1976 Mumbai Reading

124 Abhay 11-aug-1975 Allahabad Singing

125 Vishal 04-apr-1977 Delhi Swimming

128 Abinesh 10-mar-1974 Mumbai Gardening

129 Ramesh 28-oct-1981 Pune Swimming

Table : Job

Empno Area Join_Date Salary Retd_date Dept


123 Agra 25-jan-2006 50000 25-jan-2026 Marketing
127 Mathura 22-dec-2006 60000 22-dec-2026 Finance
124 Prayag 19-aug-2007 55000 19-aug-2027 Marketing
125 Gurgoan 14-apr-2004 85000 14-apr-2018 Sales
128 Pune 13-mar-2008 75000 13-mar-2028 Sales

(i) Insert a new column Phone_No in job table.


ALTER TABLE JOB ADD PHONE_NO INT;
(ii) To display Name,dept,area of employees who belong to Mumbai.
SELECT NAME, DEPT, AREA FROM PERSONAL , JOB WHERE
PERSONAL.EMPNO=JOB.EMPNO AND NATIVE_PLACE=”MUMBAI”;
(iii) To count the number of employees who joined in the year 2006.
SELECT COUNT(*) FROM JOB WHERE YEAR(JOIN_DATE)=2006;
(iv) Erase the records of employee from job table whose dept is Marketing.
DELETE FROM JOB WHERE DEPT=”MARKETING”;
Result: The above tables are created, records have been inserted, queries are executed
and outputs are verified successfully
Program 24

Title: SQL Queries-9-BOOKS Table


Question:
Write SQL queries to perform the following task on “PRACTICALS”
database with the given Table(s).
Aim:
To create the following table(s) and insert records
To execute the following queries on the created table(s)
Table: BOOKS

Book_Id Book_Name Author_Name Publishers Price Type Qty.


C0001 Fast Cook Lata Kapoor EPB 355 Cookery 5
F0001 The Tears William Hopkins First Publ. 650 Fiction 20
T0001 My First C++ Brain & Brooke EPB 350 Text 10
T0002 C++ Brainworks A.W.Rossaine TDH 350 Text 15
F0002 Thunderbolts Anna Roberts First Publ. 750 Fiction 50

(i) To show Book name, Author name and Price of books of EPB.
SELECT BOOK_NAME, AUTHOR_NAME, PRICE FROM BOOKS
WHERE PUBLISHERS=”EPB”;
(ii) To list the names from books of cookery type.
SELECT BOOK_NAME FROM BOOKS WHERE TYPE=”COOKERY”;
(iii) To display the names and price from books in ascending order of their price.
SELECT BOOK_NAME, PRICE FROM BOOKS ORDER BY PRICE;
(iv) To increase the price of all books of TDH Publishers by 3%.
UPDATE BOOKS SET PRICE=PRICE + PRICE*3/100 WHERE
PUBLISHERS=”TDH’;

Result: The above tables are created, records have been inserted, queries are executed
and outputs are verified successfully
Program 25

Title: SQL Queries-10-COLLECTIONS Table

Question:
Write SQL queries to perform the following task on “PRACTICALS”
database with the given Table(s).
Aim:
To create the following table(s) and insert records
To execute the following queries on the created table(s)

i)To display the bookname which starts with ‘T’


SELECT BOOKNAME FROM COLLECTIONS WHERE BOOKNAME LIKE “T%”;
ii)To display the records in decreasing order of bookno whose price is more than 500
SELECT * FROM COLLECTIONS WHERE PRICE > 500 ORDER BY BOOKNO DESC;
iii)To increment the quantity by 20 wherever quantity is below 50.
UPDATE COLLECTIONS SET QUANTITY = QUANTITY + 20 WHERE QUANTITY < 50;
iv)To remove the entire data from table Collections.
DELETE FROM COLLECTIONS;

Result: The above tables are created, records have been inserted, queries are executed
and outputs are verified successfully
Program -26
Title: PYTHON-SQL CONNECTIVITY- 1- Table creation and record insertion
Question :Write a menu driven program to perform the following task on “XII”
database:
i) Creating the following table “CARDEN”
ii) Inserting the given records
Ccode CarName Make Color Capacity Charges
501 A-Star Suzuki RED 3 14
503 Indigo Tata SILVER 3 12
502 Innova Toyota WHITE 7 15
509 SX4 Suzuki SILVER 4 14
510 C Class Mercedes RED 4 35

AIM :
To write a menu driven program to perform the following task on “XII” database .
CODE:

https://drive.google.com/file/d/1OKJavwkSVrbhXx9OBq3ObU1-sP6paprU/view?
usp=drive_link

Result: The above program is executed successfully and the output is verified

Program -27
Title:PYTHON-SQL CONNECTIVITY-2- Record updation

Question : Write a program to update the Rate by 5% on “orders” table of “XII”


database:

OderID Pname Quantity Rate Sale_date Discount


1001 Pen 10 20 2019-10-05 NULL
1002 Pencil 20 10 2019-10-21 NULL
1003 Book 10 100 2019-11-12 50
1004 Eraser 100 5 2019-12-05 25
1005 Copy 50 20 2019-12-10 NULL
AIM:
To Write a program to update the Rate by 5% on “orders” table of “XII” database:

CODE:

https://drive.google.com/file/d/1SCNrHjipRE0C2fzP9O1A6Vd9-Cko_SrL/view?usp=drive_link

Result: The above program is executed successfully and the output is verified

Program -28
Title: PYTHON-SQL CONNECTIVITY-3-Record deletion

Question : Write a program to delete the rows where class is 10 on “sports” table of
“XII” database:

Stud_no Class Name game1 grade1


10 7 Sameer Cricket B
11 8 Sujith Tennis A
12 7 Kamal Swimming B
13 7 Venna Tennis C
14 9 Archana Basketball A
15 10 Arpit Cricket A
AIM:
To Write a program to delete the rows where class is 10 on “sports” table of “XII”
database:

CODE:

https://drive.google.com/file/d/1XQ2HZuGWK52_08NscT8mH1L7krAbLHp0/view?usp=drive_link

Result: The above program is executed successfully and the output is verified
Program -29
Title:PYTHON-SQL CONNECTIVITY-4-Search and Display

Question : Write a program to do the following task on “students” table of “XII” database:

 To sort the records according to the students name in alphabetical order


 To display class, dob and city whose marks is between 450 and 551
 To display the highest marks class wise

AIM:
To Write a program
 To sort the records according to the students name in alphabetical order
 To display class, dob and city whose marks is between 450 and 551
 To display the highest marks class wise

CODE:
https://drive.google.com/file/d/1qSDe5T_XyLylDfGrHmdIMF0PWKagSHxI/view?usp=drive_link

Result: The above program is executed successfully and the output is verified
Program -30
Title:PYTHON-SQL CONNECTIVITY-5-Database creation ,Table creation and Table alteration

Question :Write a program to do the following:


i. To create a database “EMP”
ii. To Create the table “EMPLOYEE” with the following specification
Ecode-varchar(6)-primary key
Ename-varchar(20)- should not be blank
Sex-char
Salary-integer
Subject-varchar(20)
Joindate-date
iii. To Include a column deptname –varchar(20)
iv. To increase the size of the field subject to 30
Ecode Ename Sex Salary Subject JoinDate
F1001 Hari Charan M 101000 English 2000-10-11
F1004 Mallika F 202000 Programming 2003-11-30
F1002 Arun M 202000 Web design 2001-09-06
F1005 Priya F 201000 Web design 2004-12-15
F1009 Tanya F 203000 Programming 2006-12-31
F1006 Amar M 108000 Data structure 2005-05-02
F1008 Avinash M 105000 Maths 2002-03-15
AIM: To write a program to do the following:
i. To create a database “EMP”
ii. To Create the table “EMPLOYEE” with the following specification
Ecode-varchar(6)-primary key
Ename-varchar(20)- should not be blank
Sex-char
Salary-integer
Subject-varchar(20)
Joindate-date
iii. To Include a column deptname –varchar(20)
iv. To increase the size of the field subject to 30

CODE:

https://drive.google.com/file/d/1LY5rtRby69KiBNVnP7Sgsq7n70SX9luS/view?usp=drive_link

Result: The above program is executed successfully and the output is verified
Database Commands in MySql
1. To get list of available databases:
mysql>SHOW DATABASES;

2.To create a database:


mysql>CREATE database myschool;

3. To delete a database:
mysql>DROP database <databasename>;

4. To open the database:


mysql>USE myschool;

5. To remove table:
mysql>droptable <tablename>;
6. To show list of tables in opened database:
mysql>SHOW TABLES;

7. To create a table in the database.


mysql>CREATE TABLE student(lastname varchar(15),firstname varchar(15),city varchar(20),class char(2));

8. To view the structure of a table.


mysql>DESCRIBE student;

9. To create a table with Constraints


mysql>CREATE TABLE Persons(IDint NOT NULL PRIMARYKEY,
LastName varchar(255) NOT NULL, FirstName varchar(255),
Age int, City varchar(255) DEFAULT ‘Jaipur', CONSTRAINT CHK_Person CHECK(Age>=18));

mysql>CREATE TABLE Orders(OrderID int NOT NULL, OrderNumber int NOT NULL, PersonID int, PRIMARY
KEY(OrderID),FOREIGN KEY(PersonID) REFERENCES PERSONS(ID);

10. To insert new rows into an existing table:


mysql>INSERT INTO student values(‘dwivedi’,’freya’,’Udaipur’,’4’);

11. To insert record with specific column only:


mysql>INSERT INTO student(lastname,firstname,city) values(‘dwivedi’,’Mohak’,’Udaipur’,);

12. To select all the fields of a table:


mysql>SELECT*FROM student;
12
13. To select rows by using the WHERE:
mysql>SELECT * FROM student WHERE class=“4";

14. To select specific columns(Projection)by listing their names:


mysql>SELECT first_name,class FROM student;

15. To select rows with null values in specific column:


mysql>SELECT*FROM Student WHERE City IS NULL;

16. To select rows BETWEEN the given values in specific column:


mysql>SELECT * FROM Student WHERE class between 4and6;

17. To select rows with given list of values in specific column:


mysql>SELECT*FROM Student WHERE class in(4,5,6);

18. To select rows using LIKE operator:


mysql>SELECT* FROM Student WHERE Name LIKE ‘A%’;
mysql>SELECT * FROM Student WHERE Name LIKE ’%Singh%’;

19. To select rows using Like operator with relational and logical operator:
mysql>SELECT Name,City FROM Student WHERE Class>=8 AND Name LIKE ‘%Kumar%’;

20. To display data after removal of duplicate values from specific column:
mysql>select distinct class from student;

21. To delete selected rows from a table:


mysql>DELETE FROM student WHERE firstname=“amar";
13
22. To modify or update entries in the table:
mysql>UPDATE student SET class=“V" WHERE firstname=“freya";

23. To add a New Column inan existing tabl:


msql>ALTER TABLE ADD column_name datatype;

24. To drop column in an existing table:


mysql>ALTER TABLE student DROP marks;

25. To change the DATATYPE of a column in a table:


mysql>ALTER TABLE student change name name varchar(30);
mysql>ALTER TABLE student modify(name varchar(30));

26. To add a NOT NULL constraint to a column:


mysql>ALTER TABLE student MODIFY name varchar(30) NOTNULL;

27. To add UNIQUE CONSTRAINT to a column:


mysql>ALTER TABLE student ADD CONSTRAINT MyUnique Constraint UNIQUE(name,address);

28. To ADD CHECK CONSTRAINT to a table:


mysql>ALTER TABLE student ADD CONSTRAINT MyUnique Constraint CHECK(marks>=0);

29. To ADD PRIMARY KEY constraint to a table:


mysql>ALTER TABLE student ADD CONSTRAINT My Primary Key PRIMARY KEY(first_name,last_name);

30. To DROP CONSTRAINT from a table:


mysql>ALTER TABLE student DROP CONSTRAINT MyUnique Constraint;

14
31. To DROP PRIMARY KEY constraint from a table
mysql>ALTER TABLE student DROP CONSTRAINT MyPrimaryKey;
mysql>ALTER TABLE student DROP PRIMARY KEY;

32. To display the records in ascending order.


mysql>select * from student order by class;
mysql>select*from student order by class asc;

33. To display the records in descending order.


mysql>select*from student order by class desc;

34. To order the data on multiple columns:


mysql>select * from student order by class asc, marks asc;
mysql>select * from student order by class asc, marks desc;

35. To order the data on the basis of an expression:


mysql>select name,mark from student where marks>80 order by class;

36. To sort the data in specific order:


mysql>select*from student order by FIELD(city,’Chennai’,’Mumbai’,’Delhi’);

37. To apply Aggregate functions:


mysql>select Sum(Sal) from EMP;
mysql>select Sum(Sal) from EMP where grade=”E2”;
mysql>Select Min(Sal) from EMP;
mysql>Select Min(Sal) from EMP where(gradE=”E1”orgrade=”E2”);
mysql>Select Max(Sal) from EMP;
mysql>Select Count(Sal) from EMP;
mysql>Select Avg(Sal) from EMP;
15
mysql>Select Count(*) from Emp;

38. To group the records by column name:


msql>select class from student group by class;

39. To group the records by column name with aggregate functions:


mysql>select class,count(*) from student group by class;
mysql>select class,avg(marks) from student group by class;

40. To group the records by column with aggregate functions (with where and order by clause):
mysql>select class,avg(marks) from student where class<10 group by class order by marks desc;

41. To order the records after grouping by specific column:


mysql>select class,avg(marks) from student where class<10 group by class order by marks desc;

42. To group there cords with aggregate functions & having clause:
mysql>select class,avg(marks) from student group by class having avg(marks)<90; mysql>select
class,avg(marks) from student group by class having count(*)<3;

43. To display Cartesian product(X)/cross joint:


mysql>Select* from a,b;
mysql>Select*from a cross join b;

44. To display the records using INNER Join or EQUI Join ⋈


mysql>Select course.student_name from couse,student where course.student_name=student.student_name;
mysql>Select a.name from a inner join b on a.name=b.name;

45. To display the records using Natural JOIN(⋈)


mysql>Select*from a natural join b;

16
46. To display the records using LEFT Outer Join :
mysql>Select* from a left outer join b on(a.name=b.name);

47. To display the records using RIGHT Outer Join:


mysql>Select*from a right outer join b on(a.name=b.name);

48. To display the records using Full Outer Join:


mysql>Select*from a left outer join b on(a.name=b.name) union Select * from a right outer join b on
(a,name=b.name);

17

You might also like