0% found this document useful (0 votes)
8 views

SQL Practical - Removed Rs

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SQL Practical - Removed Rs

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Program No- 24

1. '''Program to create table student with the following structure:


Student_id int(10) primary key
Student_name varchar(20)
Class varchar (10)
City varchar(10)
Percentage float(4)
Display the structure of the table after creation'''
import mysql.connector as std
mycon=std.connect(host='localhost',\
user='root',\
password='12345678',\
database='school')
mycur=mycon.cursor()
mycur.execute('create table student (Student_id int(10) primary key,Student_name
varchar(20),Class varchar(10),city varchar(10),Percentage float(4)')
mycur.execute('desc student')
for data in mycur:
print(data)
mycon.close()

OUTPUT
Program No- 25
2. '''Program to display the detail of students whose percentage is between
80 and 98 (both values included):
Display the structure of the table after creation'''
import mysql.connector as std
mycon=std.connect(host='localhost',\
user='root',\
password='12345678',\
database='school')
mycur=mycon.cursor()
mycur.execute("select * from student where percentage between 80 and 98")
for data in mycur:
print(data)
mycon.close()

OUTPUT
Program No- 26
3. Program to increment the percentage of all student by 2. and
display the table content after updating

import mysql.connector as std


mycon=std.connect(host='localhost',\
user='root',\
password='12345678',\
database='school')
mycur=mycon.cursor()
mycur.execute("update student set percentage = percentage + 2")
mycon . commit ( )
print ( “ Record updated successfully” )
mycur.execute('desc student')
for data in mycur:
print(data)
mycon.close()

OUTPUT:
Program No- 27
4. Program to display the detail of students in ascending order of
their percentage

import mysql.connector as std


mycon=std.connect(host='localhost',\
user='root',\
password='12345678',\
database='school')
mycur=mycon.cursor()
mycur.execute("select * from student order by percentage")
for data in mycur:
print(data)
mycon.close()

OUTPUT

You might also like