Please select a subject first
Advertisements
Advertisements
A Binary file, CINEMA.DAT has the following structure:
{MNO:[MNAME, MTYPE]}
Where
- MNO - Movie Number
- MNAME - Movie Name
- MTYPE is Movie Type
Write a user defined function, findType(mtype), that accepts mtype as parameter and displays all the records from the binary file CINEMA.DAT, that have the value of Movie Type as mtype.
Concept: The Pickle Module in Python
How are text files different from binary files?
Concept: Types of Files in Python
Explain the use of ‘Foreign Key’ in a Relational Database Management System. Give example to support your answer.
Concept: Keys in a Relational Database
Explain the concept of “Alternate Key” in a Relational Database Management System with an appropriate example.
Concept: Keys in a Relational Database
The school has asked their estate manager Mr Rahul to maintain the data of all the labs in a table LAB. Rahul has created a table and entered data from 5 labs.
| LAB NO | LAB_NAME | INCNCHARGE | CAPACITY | FLOOR |
| L001 | CHEMISTRY | Daisy | 20 | I |
| L002 | BIOLOGY | Venky | 20 | II |
| L003 | MATH | Preeti | 15 | I |
| L004 | LANGUAGE | Daisy | 36 | III |
| L005 | COMPUTER | Mary | 37 | II |
Based on the data given above answer the following questions:
(i) Identify the columns which can be considered as Candidate keys.
(ii) Write the degree and cardinality of the table.
(iii) Write the statements to:
(a) Insert a new row with appropriate data.
(b) Increase the capacity of all the labs by 10 students which are on
the 'I' Floor.
OR
(iii) Write the statements to:
(a) Add a constraints PRIMARY KEY to the column LABNO in the table.
(b) Delete the table LAB.
Concept: Keys in a Relational Database
Which of the following statements is FALSE about keys in a relational database?
Concept: Keys in a Relational Database
Give one difference between alternate key and candidate key.
Concept: Keys in a Relational Database
______ command is used to remove the primary key from a table in SQL.
Concept: SQL for Data Definition
Which of the following commands will delete the table from the MYSQL database?
Concept: SQL for Data Definition
______ is a non-key attribute, whose values are derived from the primary key of some other table.
Concept: SQL for Data Definition
Which function is used to display the total number of records from a table in a database?
Concept: Functions in SQL
To establish a connection between Python and SQL databases, connect() is used. Which of the following arguments may not necessarily be given while calling connect()?
Concept: SQL for Data Definition
Differentiate between count() and count(*) functions in SQL with appropriate examples.
Concept: Functions in SQL
Consider the following tables – Bank_Account and Branch:
Table: Bank_Account
| ACode | Name | Type |
| A01 | Amrita | Savings |
| A02 | Parthodas | Current |
| A03 | Miraben | Current |
Table: Branch
| ACode | City |
| A01 | Delhi |
| A02 | Mumbai |
| A01 | Nagpur |
What will be the output of the following statement?
SELECT * FROM Bank_Account NATURAL JOIN Branch;
Concept: SQL for Data Query
Write the output of the queries based on the table, TECH_COURSE given below:
| Table: TECH_COURSE | ||||
| CID | CNAME | FEES | STARTDATE | TID |
| C201 | Animation and VFX | 12000 | 2022-07-02 | 101 |
| C202 | CADD | 15000 | 2021-11-15 | NULL |
| C203 | DCA | 10000 | 2020-10-01 | 102 |
| C204 | DDTP | 9000 | 2021-09-15 | 104 |
| C205 | Mobile Application Development |
18000 | 2022-11-01 | 101 |
| C206 | Digital Marketing | 16000 | 2022-07-25 | 103 |
- SELECT DISTINCT TID FROM TECH_COURSE;
- SELECT TID, COUNT(*), MIN(FEES) FROM TECH_COURSE GROUP BY TID HAVING COUNT(TID)>1;
- SELECT CNAME FROM TECH_COURSE WHERE FEES>15000 ORDER BY CNAME;
- SELECT AVG(FEES) FROM TECH_COURSE WHERE FEES BETWEEN 15000 AND 17000;
Concept: GROUP BY Clause in SQL
Write the outputs of the SQL queries based on the relations Teacher and Placement given below:
Table: Teacher
| T_ID | Name | Age | Department | Date_of_join | Salary | Gender |
| 1 | Arunan | 34 | Computer Sc | 2019-01-10 | 12000 | M |
| 2 | Saman | 31 | History | 2017-03-24 | 20000 | F |
| 3 | Randeep | 32 | Mathematics | 2020-12-12 | 30000 | M |
| 4 | Samira | 35 | History | 2018-07-01 | 40000 | F |
| 5 | Raman | 42 | Mathematics | 2021-09-05 | 25000 | M |
| 6 | Shyam | 50 | History | 2019-06-27 | 30000 | M |
| 7 | Shiv | 44 | Computer Sc | 2019-02-25 | 21000 | M |
| 8 | Shalakha | 33 | Mathematics | 2018-07-31 | 20000 | F |
Table: Placement
| P_ID | Department | Place |
| 1 | History | Ahmedabad |
| 2 | Mathematics | Jaipur |
| 3 | Computer Sc | Nagpur |
- SELECT Department, avg(salary) FROM Teacher GROUP BY Department;
- SELECT MAX(Date_of_Join), MIN(Date_of_Join) FROM Teacher;
- SELECT Name, Salary, T.Department, Place FROM Teacher T, Placement P WHERE T.Department = P.Department AND Salary>20000;
- SELECT Name, Place FROM Teacher T, Placement P WHERE Gender = ’F’ AND T.Department = P.Department;
Concept: Functions in SQL
Write the command to view all tables in a database.
Concept: SQL for Data Definition
Predict the output of the code given below:
s="welcome2cs"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m +s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m +'&'
print(m)Concept: Functions in SQL
The code given below reads the following record from the table named student and displays only those records that have marks greater than 75:
- RollNo - integer
- Name - string
- Clas - integer
- Marks - integer
Note the following to establish connectivity between Python and MYSQL:
- Username is root.
- The password is the tiger.
- The table exists in an MYSQL database named school.
Write the following missing statements to complete the code:
Statement 1 - to form the cursor object
Statement 2 - to execute the query that extracts records of those students whose marks are greater than 75.
Statement 3 - to read the complete result of the query (records whose marks are greater than 75) into the object named data, from the table student in the database.
import mysql.connector as mysql
def sql_data():
con1=mysql.connect(host="localhost",user="root",password="tiger", database="school")
mycursor=_______________ #Statement 1
print("Students with marks greater than 75 are :")
_________________________ #Statement 2
data=__________________ #Statement 3
for i in data:
print(i)
print()Concept: SQL for Data Definition
Navdeep creates a table RESULT with a set of records to maintain the marks secured by students in Sem1, Sem2, Sem3, and their divisions. After the creation of the table, he entered data of 7 students in the table.
| ROLL_NO | SNAME | SEM1 | SEM2 | SEM3 | DIVISION |
| 101 | KARAN | 366 | 410 | 402 | I |
| 102 | NAMAN | 300 | 350 | 325 | I |
| 103 | ISHA | 400 | 410 | 415 | I |
| 104 | RENU | 350 | 357 | 415 | I |
| 105 | ARPIT | 100 | 75 | 178 | IV |
| 106 | SABINA | 100 | 205 | 217 | II |
| 107 | NEELAM | 470 | 450 | 471 | I |
Based on the data given above answer the following questions:
- Identify the most appropriate column, which can be considered as the Primary key.
- If two columns are added and 2 rows are deleted from the table result, what will be the new degree and cardinality of the above table?
- Write the statements to:
a. Insert the following record into the table
Roll No - 108, Name - Aadit, Sem1- 470, Sem2 - 444, Sem3 - 475, Div - I.
b. Increase the SEM2 marks of the students 3% whose name begins with ‘N’.
OR
Write the statements to:
a. Delete the record of students securing IV division.
b. Add a column REMARKS in the table with datatype as varchar with 50 characters.
Concept: SQL for Data Definition
