0% found this document useful (0 votes)
32 views6 pages

Set 1

The document contains sample code and output for menu driven program to perform CRUD operations on a binary file containing shoe records and SQL queries and output on tables created in a database. The Python program allows adding, displaying, and searching shoe records stored in a binary file. The SQL questions create tables, insert sample data, perform queries like select, delete, alter table and find min, max prices grouped by company.

Uploaded by

Rashvandh
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)
32 views6 pages

Set 1

The document contains sample code and output for menu driven program to perform CRUD operations on a binary file containing shoe records and SQL queries and output on tables created in a database. The Python program allows adding, displaying, and searching shoe records stored in a binary file. The SQL questions create tables, insert sample data, perform queries like select, delete, alter table and find min, max prices grouped by company.

Uploaded by

Rashvandh
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/ 6

SET – 1

Q-1 a) Write a menu driven program to perform following operations into a binary
fileshoes.dat.
1.Add record
2.Display records
3.Search record
4.Exit
The structure of file content is: [s_id, name, brand, type, price]
SOURCE CODE:
import pickle
l=[]
found=0
def add_rec():
f=open("shoes.dat","ab")
s_id=int(input("Enter Shoes ID:"))
name=input("Enter Name:")
brand=input("Enter Brand:")
type=input("Enter Type:")
price=int(input("Enter Price:"))
l=[s_id,name,brand,type,price]
pickle.dump(l,f)
print("Record Added.")
f.close()
def dis_rec():
f=open("shoes.dat","rb")
while True:
try:
l=pickle.load(f)
print(l)
except EOFError:
f.close()
break
def search_record():
f=open("shoes.dat","rb")
s_id=int(input("Enter Shoe ID:"))
while True:
try:
l=pickle.load(f)
if l[0]==s_id:
found=1
print("Record Found:",l)
else:
found=0
except EOFError:
f.close()
break
if found==0:
print("Record Not Found!")
while True:
print('''
1. Add Record
2. Display Record
3. Search Record
4. Exit
''')
ch=int(input("Enter your choice:"))
if ch==1:
add_rec()
elif ch==2:
dis_rec()
elif ch==3:
search_record()
elif ch==4:
break
else:
print("Invalid Choice!")
OUTPUT:

Q-1 b) Write SQL command and output for the following queries using the
Relation- STU(4)
mysql> CREATE DATABASE SCHOOL;
Query OK, 1 row affected (0.20 sec)

mysql> USE SCHOOL;


Database changed
mysql> CREATE TABLE STU
-> (Rollno INTEGER,
-> Name varchar(15),
-> Gender varchar(2),
-> Age int(3),
-> Dept varchar(15),
-> DOA date,
-> Fees integer(5) );
Query OK, 0 rows affected, 2 warnings (0.32 sec)

mysql> INSERT INTO STU


-> VALUES(1,'Arun','M',24,'COMPUTER','1997-01-10',120);
Query OK, 1 row affected (0.11 sec)

mysql> INSERT INTO STU


-> VALUES(2,'Ankit','M',21,'HISTORY','1998-03-24',200);
Query OK, 1 row affected (0.10 sec)

mysql> INSERT INTO STU


-> VALUES(3,'Anu','F',20,'HINDI','1996-12-12',300);
Query OK, 1 row affected (0.04 sec)

mysql> INSERT INTO STU VALUES(4,'Bala','M',19,NULL,'1997-07-01',400);


Query OK, 1 row affected (0.06 sec)

mysql> INSERT INTO STU VALUES(5,'Cheran','M',18,'HINDI','1997-09-05',250);


Query OK, 1 row affected (0.06 sec)

mysql> INSERT INTO STU


-> VALUES(6,'Deepa','F',19,'HISTORY','1997-06-27',300);
Query OK, 1 row affected (0.06 sec)

mysql> INSERT INTO STU


-> VALUES(7,'Dinesh','M',22,'COMPUTER','1997-02-25',210);
Query OK, 1 row affected (0.05 sec)

mysql> INSERT INTO STU


-> VALUES(8,'Usha','F',23,NULL,'1997-07-31',200);
Query OK, 1 row affected (0.06 sec)

mysql> SELECT * FROM STU;


+--------+--------+--------+------+----------+------------+------+
| Rollno | Name | Gender | Age | Dept | DOA | Fees |
+--------+--------+--------+------+----------+------------+------+
| 1 | Arun | M | 24 | COMPUTER | 1997-01-10 | 120 |
| 2 | Ankit | M | 21 | HISTORY | 1998-03-24 | 200 |
| 3 | Anu | F | 20 | HINDI | 1996-12-12 | 300 |
| 4 | Bala | M | 19 | NULL | 1997-07-01 | 400 |
| 5 | Cheran | M | 18 | HINDI | 1997-09-05 | 250 |
| 6 | Deepa | F | 19 | HISTORY | 1997-06-27 | 300 |
| 7 | Dinesh | M | 22 | COMPUTER | 1997-02-25 | 210 |
| 8 | Usha | F | 23 | NULL | 1997-07-31 | 200 |
+--------+--------+--------+------+----------+------------+------+
8 rows in set (0.00 sec)

a)
mysql> SELECT Name FROM STU WHERE Name LIKE '_n%';
+-------+
| Name |
+-------+
| Ankit |
| Anu |
+-------+
2 rows in set (0.00 sec)

b)
mysql> DELETE FROM STU WHERE Rollno = 8;
Query OK, 1 row affected (0.10 sec)

mysql> SELECT * FROM STU;


+--------+--------+--------+------+----------+------------+------+
| Rollno | Name | Gender | Age | Dept | DOA | Fees |
+--------+--------+--------+------+----------+------------+------+
| 1 | Arun | M | 24 | COMPUTER | 1997-01-10 | 120 |
| 2 | Ankit | M | 21 | HISTORY | 1998-03-24 | 200 |
| 3 | Anu | F | 20 | HINDI | 1996-12-12 | 300 |
| 4 | Bala | M | 19 | NULL | 1997-07-01 | 400 |
| 5 | Cheran | M | 18 | HINDI | 1997-09-05 | 250 |
| 6 | Deepa | F | 19 | HISTORY | 1997-06-27 | 300 |
| 7 | Dinesh | M | 22 | COMPUTER | 1997-02-25 | 210 |
+--------+--------+--------+------+----------+------------+------+
7 rows in set (0.00 sec)

c)
mysql> ALTER TABLE STU ADD(Area varchar(15));
Query OK, 0 rows affected (0.29 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> SELECT * FROM STU;


+--------+--------+--------+------+----------+------------+------+------+
| Rollno | Name | Gender | Age | Dept | DOA | Fees | Area |
+--------+--------+--------+------+----------+------------+------+------+
| 1 | Arun | M | 24 | COMPUTER | 1997-01-10 | 120 | NULL |
| 2 | Ankit | M | 21 | HISTORY | 1998-03-24 | 200 | NULL |
| 3 | Anu | F | 20 | HINDI | 1996-12-12 | 300 | NULL |
| 4 | Bala | M | 19 | NULL | 1997-07-01 | 400 | NULL |
| 5 | Cheran | M | 18 | HINDI | 1997-09-05 | 250 | NULL |
| 6 | Deepa | F | 19 | HISTORY | 1997-06-27 | 300 | NULL |
| 7 | Dinesh | M | 22 | COMPUTER | 1997-02-25 | 210 | NULL |
+--------+--------+--------+------+----------+------------+------+------+
7 rows in set (0.00 sec)

TABLE CREATION : COST


mysql> CREATE TABLE COST
-> (Ucode integer,
-> Size char(3), Price integer, Company varchar(20));
Query OK, 0 rows affected (0.34 sec)

mysql> INSERT INTO COST(Ucode,Size,Price,Company)


-> VALUES(1,'M',500,'RAYMOND');
Query OK, 1 row affected (0.06 sec)

mysql> INSERT INTO COST(Ucode,Size,Price,Company)


-> VALUES(1,'L',580,'MATTEX');
Query OK, 1 row affected (0.07 sec)

mysql> INSERT INTO COST(Ucode,Size,Price,Company)


-> values(2,'XL',620,'MATTEX');
Query OK, 1 row affected (0.05 sec)

mysql> INSERT INTO COST(Ucode,Size,Price,Company)


-> values(2,'M',810,'YASIN');
Query OK, 1 row affected (0.05 sec)

mysql> INSERT INTO COST(Ucode,Size,Price,Company)


-> VALUES(2,'L',940,'raymond');
Query OK, 1 row affected (0.06 sec)

mysql> insert into cost


-> values(3,'M',770,'Yasin');
Query OK, 1 row affected (0.06 sec)

mysql> insert into cost


-> values(3,'L',830,'Galin');
Query OK, 1 row affected (0.07 sec)

mysql> select * from cost;


+-------+------+-------+---------+
| Ucode | Size | Price | Company |
+-------+------+-------+---------+
| 1 | L | 580 | MATTEX |
| 2 | XL | 620 | MATTEX |
| 2 | M | 810 | YASIN |
| 2 | L | 940 | raymond |
| 3 | M | 770 | Yasin |
| 3 | L | 830 | Galin |
+-------+------+-------+---------+
6 rows in set (0.00 sec)

d.) mysql> select company,min(price),max(price) from cost group by(company);


+---------+------------+------------+
| company | min(price) | max(price) |
+---------+------------+------------+
| MATTEX | 580 | 620 |
| YASIN | 770 | 810 |
| raymond | 940 | 940 |
| Galin | 830 | 830 |
+---------+------------+------------+
4 rows in set (0.00 sec)

You might also like