CBSE Class 12 Computer Science
Question 42 of 42
Solved 2024 Sample Question Paper CBSE Class 12 Computer Science (083) — Question 5
Back to all questions 5
Question (i) Give one difference between alternate key and candidate key.
(ii) Sartaj has created a table named Student in MYSQL database, SCHOOL:
- rno(Roll number )- integer
- name(Name) - string
- DOB (Date of birth) – Date
- Fee – float
Note the following to establish connectivity between Python and MySQL:
- Username - root
- Password - tiger
- Host - localhost
Sartaj, now wants to display the records of students whose fee is more than 5000. Help Sartaj to write the program in Python.
(i) One difference between alternate key and candidate key:
| Alternate Key | Candidate Key |
|---|---|
| A candidate key is a set of attributes (columns) in a table that uniquely identifies each record or row. | An alternate key is a set of attributes (columns) in a table that uniquely identifies each record but is not designated as the primary key. |
(ii)
import mysql.connector as mysql
con1 = mysql.connect(host = "localhost",
user = "root",
password = "tiger",
database = "SCHOOL")
mycursor = con1.cursor()
query = "SELECT * FROM student WHERE fee > {}".format(5000)
mycursor.execute(query)
data = mycursor.fetchall()
for rec in data:
print(rec)
con1.close()