0% found this document useful (0 votes)
61 views4 pages

Set 2

The document describes a MySQL database called SCHOOL that contains a table named STU for student records. It shows the creation of the STU table with various fields, insertion of sample records, and use of SQL queries to select, update and alter the table. Records are inserted for 8 students, SELECT queries are used to retrieve records by department and update a fee amount, and the table is altered to add a new Area field.

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)
61 views4 pages

Set 2

The document describes a MySQL database called SCHOOL that contains a table named STU for student records. It shows the creation of the STU table with various fields, insertion of sample records, and use of SQL queries to select, update and alter the table. Records are inserted for 8 students, SELECT queries are used to retrieve records by department and update a fee amount, and the table is altered to add a new Area field.

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/ 4

SET – 2

Q-1 a)Write a menu driven python program to create a stack of a student's record
which contains [admo, marks ]. (8) i)Write function PUSH to add record in to the
stack and
ii)Write a function DISPLAY to display those students whose marks are greater
than 70.
SOURCE CODE:
students=[]
def PUSH():
admo=int(input("Enter the admission number of the student:"))
marks=int(input("Enter the marks of the student:"))
l=[admo,marks]
students.append(l)
def DISPLAY():
for rec in students:
if rec[1]>70:
print(rec)
while True:
print('''
1. Push
2. Display
3. Exit
''')
ch=int(input("Enter your choice:"))
if ch==1:
PUSH()
elifch==2:
DISPLAY()
elifch==3:
break
else:
print("Invalid Choice!")
OUTPUT:

1. B.

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 * FROM STU WHERE DEPT='HISTORY';


+--------+-------+--------+------+---------+------------+------+
| Rollno | Name | Gender | Age | Dept | DOA | Fees |
+--------+-------+--------+------+---------+------------+------+
| 2 | Ankit | M | 21 | HISTORY | 1998-03-24 | 200 |
| 6 | Deepa | F | 19 | HISTORY | 1997-06-27 | 300 |
+--------+-------+--------+------+---------+------------+------+
2 rows in set (0.00 sec)

b) UPDATE STU SET Fees = 170 WHERE Rollno = 1 AND Fees < 130;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0

output:
mysql> select * from stu;
+--------+--------+--------+------+----------+------------+------+
| Rollno | Name | Gender | Age | Dept | DOA | Fees |
+--------+--------+--------+------+----------+------------+------+
| 1 | Arun | M | 24 | COMPUTER | 1997-01-10 | 170 |
| 2 | Ankit | M | 21 | HISTORY | 1998-03-24 | 200 |
| 3 | Anu | F | 20 | HINDI | 1996-12-12 | 300 |
| 4 | Bala | M | 19 | NULL | 1999-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 |
+--------+--------+--------+------+----------+------------+------+

c)ALTER TABLE STU ADD(Area varchar(10));


Query OK, 0 rows affected (0.20 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 | 170 | 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 | 1999-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 |
| 8 | Usha | F | 23 | NULL | 1997-07-31 | 200 | NULL |
+--------+--------+--------+------+----------+------------+------+------+

d)ALTER TABLE STU ADD(Area varchar(10)); same output as (c)

You might also like