Professional Documents
Culture Documents
CS Tareshan
CS Tareshan
Date : 6.9.2022
AIM : To understand the creation, Display, insertion of records, applying constraints
TASK : Create table TRAINER in My SQL, apply constraints , insert records and DISPLAY them.
1. Create the tables TRAINER with the given attributes and CONSTRAINTS. TrainingID as PRIMARY
KEY, name as NOT NULL, Email as UNIQUE, city as DEFAULT Faridabad.
3. Display all the records
4. To display name, email and fees only.
SCREENSHOTS:-
1. Create the tables TRAINER with the given attributes and CONSTRAINTS. TrainingID as PRIMARY
KEY, name as NOT NULL, Email as UNIQUE, city as DEFAULT Faridabad.
1
3. Display all the records
2
PRACTICAL RECORD-18
Date : 10.10.2022
AIM : To understand Applying formula, relational & logical operators in WHERE clause.
TASK :
SCREENSHOTS:-
3
4. Display the record whose fees below 1500.
5. Display the record of those students who reside in UP with marks is above 80.
4
7. Display the name, fees and marks of students whose DOB is before 2007.
5
PRACTICAL RECORD-19
Date : 11.10.2022
AIM : To understand various DML commands/clauses
TASK : Write the SQL queries from the STUDENT table. Also mention the
command/clauses used in each query.
COMMAND:- Select
CLAUSES:- From,Where,Between,And
2. Display the name and city whose email ID is not mentioned.
COMMAND:- Select
CLAUSES:- From,Where,Is
6
3. Display the record whose city is available.
COMMAND:- Select
CLAUSES:- From,Where,Is not
COMMAND:- Select
CLAUSES:- From,Order by,Desc
7
6.Display the record whose year of birth is 2005.
COMMAND - SELECT
CLAUSES - FROM, WHERE, LIKE
7.Display name , fees, city and email whose name ends with "A".
COMMAND - SELECT
8
8.Arrange the records alphabetically according to name whose city is mentioned.
COMMAND - SELECT
9
PRACTICAL RECORD-20
Date : 12.10.2022
AIM : To understand DDL or DML commands/clauses.
TASK : Write the appropriate queries. Also mention CLAUSES/COMMANDS used for the
following queries:
1. Create table TRAVEL and apply constraints Primary key for CNO and NOT NULL for name.
10
3. Add a new column "CITY" with appropriate datatype.
4. Delete the rows from the table whose name ends with "h".
11
6. Rename the column CNAME to Name.
12
9. Increase the KM by 20 whose KM is below 100.
13
PRACTICAL RECORD-21
Date : 14.Oct. 2022
AIM : To understand the My SQL AGGREGATE functions
TASK : Write the appropriate queries for the following statements:
SCREENSHOTS:-
1. create table STOCK and apply constraints PID as Primary key, PName as NOT NULL, Category,
Qty is default 5, Price.
14
3.Display the lowest price of the NW category.
4.Display the total Stock available of the Keyboard, Monitor, and printer
15
6.Display the number of records.
16
PRACTICAL RECORD- 22
Date : 19.Oct. 2022
AIM : To understand the Group by and having clause
TASK : Write the appropriate queries for the following statements:
SCREENSHOTS:-
17
4. Display the highest salary earned by each category of gender.
6. Display the department and number of faculty of each department whose age is below 36
18
7. Add Primary Key to the column T_id.
19
PRACTICAL RECORD-23
Date : 21.Oct. 2022
AIM : To understand the JOINS ( Equi join, Natural join and Cartesian product)
TASK : Write the appropriate queries for the following statements:
SCREENSHOTS:-
1. Create Table Department with given values and also display the faculty table.
20
2. Display the record from both the tables. (use Cartesian product)
3. Display faculty name, department name with respective department id of each employee
whose salary is more than 20000.
21
5.Display the record from both the tables using Natural Join.
PRACTICAL RECORD-24
Date : 2.Nov. 2022
AIM : To understand connectivity functions- connect(), cursor(), execute(), fetchall()
TASK : Write a program to establish connectivity between MySQL and python and perform
the following operations:
OUTPUT:-
22
SOUCE CODE:-
import mysql.connector
con=mysql.connector.connect(
host="localhost",
user="root",
password="tiger",
database="system33",
)
cur=con.cursor()
def All():
cur.execute("select * from faculty")
x=cur.fetchall()
print("T_id","\t","Name".ljust(12),"Age"," \t","Department".ljust(18),"DOJ","\t\t","Salary","\
t","Gender")
print()
for i in x:
print(i[0],"\t",i[1].ljust(12),i[2]," \t",i[3].ljust(18),i[4],"\t\t",i[5],"\t\t",i[6])
def many():
23
cur.execute ("select * from faculty where department='history'")
v=cur.fetchall()
print("T_id","\t","Name".ljust(12),"Age"," \t","Department".ljust(18),"DOJ","\t\t","Salary","\
t","Gender")
print()
for i in v:
print(i[0],"\t",i[1].ljust(12),i[2]," \t",i[3].ljust(18),i[4],"\t\t",i[5],"\t\t",i[6])
ch="y"
while ch=="y" or "Y":
print(36 * "*")
print("*"*15,"MENU",15*"*")
print("1. All records from faculty table")
print("2. Records of history table")
print("*"*36)
c=int(input("Enter your choice:"))
if c==1:
All()
elif c==2:
many()
ch=input("do u want to cont:")
PRACTICAL RECORD-25
Date : 9.Nov. 2022
AIM : To understand creation and insertion in SQL & use of COMMIT
TASK : Write a menu driven program to establish connectivity between MySQL python and perform
the following operations:
1. Creation of CARS table
2. Insertion of CARS RECORD
3. Display the entire record
OUTPUT:-
24
SOURCE CODE:-
25
cur = con.cursor() def
CREATE():
query = """CREATE TABLE Cars(Car_ID int primary key,
Carname varchar(30),
Company varchar(30),
Model int,
Price int)"""
cur.execute(query) con.commit()
print() print("Table created successfully!!")
print()
def DISPLAY():
print("ID ","CAR NAME".ljust(10),"COMPANY".ljust(10),"MODEL","PRICE") q = "SELECT *
FROM cars"
cur.execute(q) x =
cur.fetchall() for i in x:
print(i[0],i[1].ljust(10),i[2].ljust(10),i[3]," ",i[4])
26
c1 = int(input("Enter your choice: ")) print()
if c1 == 1: CREATE() elif c1 == 2:
INSERT() elif c1 == 3:
DISPLAY()
else:
print("*"*20,"INVALID INPUT","*"*20)
print() c = input("Do you want to continue(y/n): ")
print()
else:
print("*"*20,"THANK YOU","*"*20)
PRACTICAL RECORD-26
Date : 15.Nov. 2022
AIM : To understand searching from SQL database and creating interface using Tkinter
TASK : Create an interface that takes the car name and search the record from the SQL
database. Program should display the entire record on the form.
OUTPUT:-
27
28
29
SOURCE CODE:-
a.place(x=200,y=0)
l=Label(text="Enter Car Name:",bg="yellow",fg="purple",relief=RAISED)
l.place(x=130,y=70)
p=Entry(m,width=20)
p.place(x=250,y=70)
b=Label(text="Car Id:",width=15,bg="yellow",fg="purple",relief=RAISED)
b.place(x=130,y=200)
c=Label(text="Car Company:",width=15,bg="yellow",fg="purple",relief=RAISED)
c.place(x=130,y=240)
d=Label(text="Car Model:",width=15,bg="yellow",fg="purple",relief=RAISED)
d.place(x=130,y=280)
e=Label(text="Car Price:",width=15,bg="yellow",fg="purple",relief=RAISED)
e.place(x=130,y=320)
def Search():
name=p.get()
import mysql.connector
con=mysql.connector.connect(
host="localhost",
user="root",
password="tiger",
database="system33"
)
cur=con.cursor()
q="select * from car where carname='"+name+"'"
cur.execute(q)
x=cur.fetchone()
b=Label(text=x[0],width=15,bg="orange",fg="black",relief=RAISED)
b.place(x=250,y=200)
c=Label(text=x[2],width=15,bg="orange",fg="black",relief=RAISED)
c.place(x=250,y=240)
d=Label(text=x[3],width=15,bg="orange",fg="black",relief=RAISED)
d.place(x=250,y=280)
e=Label(text=x[4],width=15,bg="orange",fg="black",relief=RAISED)
e.place(x=250,y=320)
b=Button(m,text="SUBMIT",width=20,bg="black",fg="white",command=Search)
b.place(x=170,y=150)
m.mainloop()
30
PRACTICAL 27
Date : 16.Nov. 2022
AIM : To understand UPDATION OF RECORDS from SQL database.
TASK : Write a program to update the record. Program should takes CARID from the user
that check the existence of the record.
If record found, Menu will be displayed for getting the updating choice. Update the
desired record in SQL.
Display the appropriate message if CARID not found
Output:-
31
32
SOURCE CODE:-
import mysql.connector
con=mysql.connector.connect(
host="localhost",
user="root",
password="tiger",
database="system33",
)
cur=con.cursor()
print("*"*30)
print("\t UPDATION")
print("*"*30)
print()
33
cur.execute(q3)
print("Model Updated!!")
elif c==4:
p=int(input("enter price to update"))
q4='''update car
set price={}
where carid={}'''.format(p,x)
cur.execute(q3)
print("Price Updated!!")
cur.execute("commit")
con.close()
34
PRACTICAL RECORD-28
OUTPUT:-
35
36
SOURCE CODE:-
m = Tk()
m.title("CARS")
m.geometry("350x450")
m.configure(bg="sky blue") l =
Label(text="DELETION",bg="yellow",relief="raised",font="Helvatica 25 underline")
l.place(x=100,y=10)
f = Frame(m,bg="Yellow",width=330,height=180)
f.place(x=10,y=250)
i = PhotoImage(file="car.png") k =
Label(m,image=i,bg="sky blue")
k.place(x=90,y=80)
p = Entry(width=20)
p.place(x=180,y=260)
def DELETE():
ID=p.get() con =
mysql.connector.connect( h
ost = "localhost", user =
"root", password = "tiger",
database = "system33")
37
q1 = "DELETE FROM cars WHERE car_ID='"+ID+"'"
cur.execute(q1)
con.commit()
l= Label(text="RECORD DELETED SUCCESSFULLY",bg="sky blue",fg="black",font="Helvatica
12 underline")
l.place(x=50,y=370)
else:
l=Label(text="RECORD NOT FOUND",bg="sky blue",fg="black",font="Helvatica 15 underline")
l.place(x=80,y=370) con.close()
b = Button(text="DELETE",command=DELETE)
b.place(x=150,y=300)
m.mainloop()
38