import mysql.connector
mycon = mysql.connector.connect(
host='localhost',
user='root',
password='password',
database='School')
if mycon.is_connected():
print('Database connected')
cursor = mycon.cursor()
# Display all the records of students in ascending order of Name:
sql ="SELECT * FROM STUDENT ORDER BY Name"
cursor.execute(sql)
data = cursor.fetchall()
print("Answer for a):")
for rec in data:
print(rec)
# Display the number of records whose name starts with 'D':
sql ="SELECT COUNT(*) FROM STUDENT WHERE Name LIKE
'D%'"
cursor.execute(sql)
count = cursor.fetchone()[0]
print("The number of records whose name starts with 'D' is{count}")
# Delete the record whose ID is 3
sql ="DELETE FROM STUDENT WHERE ID =3"
cursor.execute(sql)
mycon.commit()
print("Record Deleted")
mycon.close()