Advertisements
Advertisements
Question
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.
Solution
import mysql.connector as mysql
con1 = mysql.connect (host="localhost", user="root", password="tiger", database="sample2023")
mycursor=con1.cursor()
query = "SELECT * FROM student where fee>{}".format (5000)
mycursor.execute(query)
data=mycoursor.fetchall()
for rec in data:
print (rec)
con1.close()
APPEARS IN
RELATED QUESTIONS
Which of the following is not a valid SQL type?
MySQL is not:
In database, a column is known as:
What does data type indicate?
______ decides the operations that can be performed on an attribute.
Which datatype specifies character type data of length where n could be any value from 0 to 65535?
Date datatype is stored as:
Restrictions on the type of values that an attribute can have are referred to as:
Using the sports database containing two relations (TEAM, MATCH_DETAILS) and write the Query for the following:
Change the name of the relation TEAM to T_DATA. Also, change the attributes TeamID and TeamName to T_ID and T_NAME respectively.
Differentiate between CHAR and VARCHAR data types in SQL with appropriate examples.
In a table in the MYSQL database, an attribute A of datatype varchar(20) has the value “Keshav”. The attribute B of datatype char(20) has the value “Meenakshi”. How many characters are occupied by attribute A and attribute B?
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.
Zack is working in a database named SPORT, in which he has created a table named “Sports” containing columns SportId, SportName, no_of_players, and category.
After creating the table, he realized that the attribute, category has to be deleted from the table and a new attribute TypeSport of data type string has to be added. This attribute TypeSport cannot be left blank. Help Zack write the commands to complete both the tasks.