KnowledgeBoat Logo

Computer Science

(i) Define the term Domain with respect to RDBMS. Give one example to support your answer.

(ii) Kabir wants to write a program in Python to insert the following record in the 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

The values of fields rno, name, DOB and fee has to be accepted from the user. Help Kabir to write the program in Python.

Python MySQL

2 Likes

Answer

(i) Domain is a set of values from which an attribute can take value in each row.
For example, roll no field can have only integer values and so its domain is a set of integer values.

(ii)

import mysql.connector as mysql
con1 = mysql.connect(host = "localhost",
                     user = "root",
                     password = "tiger",
                     database = "SCHOOL")
mycursor = con1.cursor()
rno = int(input("Enter Roll Number:: "))
name = input("Enter the name:: ")
DOB = input("Enter date of birth:: ")
fee = float(input("Enter Fee:: "))
query = "INSERT into student values({}, '{}', '{}', {})".format(rno, name, DOB, fee)
mycursor.execute(query)
con1.commit()
print("Data added successfully")
con1.close()

Answered By

1 Like


Related Questions