Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 38

PRACTICAL RECORD-17

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.

2. Insert the given records in a table.

1
3. Display all the records

4. To display name, email and fees only.

2
PRACTICAL RECORD-18

Date          :    10.10.2022
AIM           :    To understand Applying formula, relational & logical operators in WHERE clause.
TASK        :    

SCREENSHOTS:-

1. Create table STUDENT in My SQL with appropriate constraints.

2.  Display the entire records.

3.  Display the name, fees and discount_in_fees (Discount is 2% of fees)

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.

6.  Display the record whose city is other than Delhi.

4
7. Display the name, fees and marks of students whose DOB is before 2007.

8. Display different cities from the table.

9.  Display the records of students whose marks is 78,88,92.

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.

1.  Display the records whose marks is in range 60 to 80.

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

4.  Arrange in descending order of fees.

COMMAND:- Select
CLAUSES:- From,Order by,Desc

5.Display the records whose name starts with T.


COMMAND - SELECT

CLAUSES - FROM, WHERE, LIKE

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

CLAUSES - FROM, WHERE, LIKE

8
8.Arrange the records alphabetically according to name whose city is mentioned.
COMMAND - SELECT

CLAUSES - FROM, WHERE, IS, ORDER BY

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.
     

2. INSERT the appropriate values.

10
3. Add a new column  "CITY" with appropriate datatype.

4. Delete the rows from the table whose name ends with "h".

5. Change the data type of column "KM" to float.

11
6. Rename the column CNAME to Name.

7. Delete a column CITY.

8. Add 270 KM in John's record

12
9. Increase the KM by 20 whose KM is below 100.

10. Add a new column Fare.

11. Add the new fare values by 120*KM.

12. Decrease the fare of customer  101,103,105  by 2% of fare.

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.

2.Display the highest and the lowest price.

14
3.Display the lowest price of the NW category.

4.Display the total Stock available of the Keyboard, Monitor, and printer

5.Display the average price from the entire company stock

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:-

1.   Create Table Teacher with given values.

2.   Display the number of teachers department wise.

3.   Display the number of male and female faculty of the school

17
4.   Display the highest salary earned by each category of gender.

5.   Display the total salary by each department of school.

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.

8.  Display the department whose no. of faculty is more than 1.

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.

4.Display faculty name, salary, department name and Dept. ID of all faculties.

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:

1. To display  all records from faculty table.


2. To display and count the faculty records of History department.

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:-

import mysql.connector con


mysql.connector.connect( host =
"localhost", user = "root", password
= "tiger", database = "system33"
)

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 INSERT(): if con.is_connected() ==


'False':
print("*"*11,"Connection is not established!!","*"*11)
else:
ID = int(input("Enter the car ID : ")) name = input("Enter the car name : ") comp =
input("Enter the car company : ") model = int(input("Enter the car model : ")) price =
int(input("Enter the car price : ")) q = "INSERT INTO cars VALUES({},'{}','{}',{},
{})".format(ID,name,comp,model,price)
cur.execute(q) con.commit()

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])

c = "y" while c.lower() == "y":


print("*"*15,"CONNECTIVITY OPERATIONS","*"*15) print(" 1.
CREATION OF CARS TABLE") print(" 2. INSERTION OF CARS RECORD")
print(" 3. DISPLAY THE ENTIRE RECORD")
print("*"*55) print()

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:-

from tkinter import *


m=Tk()
m.title("Extract Data")
m.configure(bg="cyan")
m.geometry("500x600")
a=Label(text="SEARCHING CARS",bg="skyblue",fg="white",relief=RAISED)

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()

x=input("Enter the CarId:")


q="select * from car where carid="+x
cur.execute(q)
rs=cur.fetchone()
if rs==None:
    print("Record not found")
else:
    
        print("What do u want to update")
        
        print("1. Carname")
        print("2. Company")
        print("3. Model")
        print("4. price")
        print()
        c=int(input("Enter your choice:"))
        if c==1:
            n=input("Enter carname to update:")
            q2='''update car
                  set carname="{}"
                  where carid={}'''.format(n,x)
            cur.execute(q2)
            print("CarName Updated!!")
        elif c==2:
            com=input("enter Company to update")
            q3='''update car
                  set company="{}"
                  where carid={}'''.format(com,x)
            cur.execute(q3)
            print("Company Updated!!")
        elif c==3:
            m=int(input("enter model to update"))
            q3='''update car
                  set model={}
                  where carid={}'''.format(m,x)

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

Date : 22.Nov. 2022


AIM : To understand DELETION OF RECORDS from SQL database & Frame and
photo on Tkinter.
TASK : Create an interface that DELETE the record from the database. Program should takes
CARID from the user that check the existence of the record in database.

OUTPUT:-

35
36
SOURCE CODE:-

from tkinter import *


import mysql.connector

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)

l = Label(text="Enter the car ID:",bg = "sky blue",fg="black",relief="raised") l.place(x=50,y=260)

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")

cur = con.cursor() q = "Select * from cars


where car_id = '"+ID+"'" cur.execute(q) x=
cur.fetchone() if x != None:

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

You might also like