1.

Considers the following tables appointments and students and write the python script to display the following output?RollnoSnameDutyAge1AkshayPrefect172AravindSecretary16

Answer»

Given:

Student → Table Rollno, Sname, grade, gender, average, birth-date

Appointment → rollno, duty, age

Example

import sqlite3

connection = sqlite3.connect(“Academy.db”) cursor = connection.cursor( )

cursor.execute(“””DROP TABLE Appointment;”””) sql_command = “””

CREATE TABLE Appointment(rollnointprimarkey,Dutyvarchar(10),age int)”””

cursor.execute(sqlcommand)

sql command – ‘””INSERT INTO Appointment (Rollno,Duty ,age)

VALUES (“1” , “Prefect” , “17”);”””

cursor, execute(sql_command)

sql_command = ”””INSERT INTO Appointment (Rollno,Duty, age)

VALUES (“2” , “Secretary” , “16”);””” 

cursor.execute(sql_command)

# never forget this, if you want the changes to be saved:

connection.commit( )

cursor.execute(“SELECT student.rollno,student.sname,Appointment. 

Duty,Appointment.Age FROM student,Appointment where student.

rollno= Appointment.rollno”)

#print (cursor.description) to display the field names of the table

co= [i[0] for i in cursor.description] print(co)

# Field informations can be readfrom cursor.description.

result = cursor. fetchall( )

for r in result:

print(r)

OUTPUT

[‘Rollno’, ‘Sname’ , ‘Duty’ , ‘age’]

(1, ‘Akshay’ , ‘Prefect’ , 17)

(2, ’Aravind’ , ’Secretary’ , 16)



Discussion

No Comment Found