KnowledgeBoat Logo
|

Computer Science

(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.

Python MySQL

14 Likes

Answer

(i) One difference between alternate key and candidate key:

Alternate KeyCandidate 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()

Answered By

4 Likes


Related Questions