MY SQL
Ex no.16 Queries Set 1 (DDL Commands)
Suppose your school management has decided to conduct cricket matches between students of Class
XI and Class XII. Students of each class are asked to join any one of the four teams – Team Titan,
Team Rockers, Team Magnet and Team Hurricane. During summer vacations, various matches will
be conducted between these teams. Help your sports teacher to do the following:
1. Create a database “Sports”.
2. Create a table “TEAM” with following considerations:
a. It should have a column TeamID for storing an integer value between 1 to 9, which refers
to unique identification of a team.
b. Each TeamID should have its associated name (TeamName), which should be a string
of length not more than 10 characters.
c. Using constraint, make TeamID as the primary key.
d. Show the structure of the table TEAM using a SQL statement.
e. As per the preferences of the students four teams were formed as given below. Insert
these four rows in TEAM table:
i. Row 1: (1, Titan)
ii. Row 2: (2, Rockers)
iii. Row 3: (3, Magnet)
iv. Row 4: (4, Hurricane)
f. Show the contents of the table TEAM using a DML statement.
g. Now create another table MATCH_DETAILS and insert data as shown below. Choose
appropriate data types and constraints for each attribute.
Second Team
MatchID MatchDate First TeamID Second TeamID First Team Score
Score
M1 2018-07-17 1 2 90 86
M2 2018-07-18 3 4 45 48
M3 2018-07-19 1 3 78 56
M4 2018-07-19 2 4 56 67
M5 2018-07-18 1 4 32 87
M6 2018-07-17 2 3 67 51
SQL Queries and Output:
1.Database Creation:
Query:
Output:
2. TEAM Table Creation:
a, b &c. Creation of table
Query:
Output:
(a),(b)&(c)
d. Display the structure of table
Query:
Output:
e. Inserting into table
Query:
Output:
f. To show records
Query:
Output:
g. Creation of new table
Query:
Output:
EX.No.17 Queries Set 2 (Database Fetching records)
[1] Consider the following MOVIE table and write the SQL queries based on it.
Release Production Business
Movie_ID MovieName Type Date Cost Cost
M001 The Kashmir Files Action 2022-01-26 1245000 1300000
M002 Attack Action 2022-01-28 1120000 1250000
M003 Looop Lapeta Thriller 2022-02-01 250000 300000
M004 Badhai Do Drama 2022-02-04 720000 68000
M005 Shabaash Mithu Biography 2022-02-04 1000000 800000
1. Display all the records from the table movie.
2. Display the different type of movies.
3. Display movieid, moviename, total earning by calculating business done by movie using the
sum of production cost and business cost .
4. Display movieid, moviename and productioncost for all movies with productioncost greater than
150000 and less than 1000000.
5. Display the movie of type action and romance.
6. Display the list of movies which are going to release in February, 2022.
1.Query:
Output:
2.Query:
Output:
3.Query:
Output:
4. Query:
Output:
5.Query:
Output:
6.Query:
Output:
EX.No.18 Queries set 3 (Based on Two Tables)
In a company database, there are two tables given below :
Table:JOB Table : EMPLOYEE
EMPI NAME SALES JOBID
JOBID JOBTITLE SALARY D
101 President 200000 E1 SUMIT SINGH 1100000 102
102 Vice President 125000 E2 VIJAY 1300000 101
103 Administration Assistant 80000 E3 AJAY 1400000 103
104 Accounting Manager 70000 E4 MOHIT SINGH 1250000 102
105 Accountant 65000 E5 SHAILU 1450000 103
106 Sales Manager 80000
Write SQL Queries for the following :
1. To display employee ids, names of employees, job ids with corresponding job titles.
2. To display names of employees, sales and corresponding job titles who have achieved sales more than
1300000.
3. To display names and corresponding job titles of those employees who have 'SINGH' (anywhere) in
their names.
4. Show employee name ,job title and salary of those employees who are working in any one of the
mentioned job( President,Vice President, Accountant)
5. Write SQL command to change the JOBID to 104 of the EMPLOYEE with ID as E4 in the table
'EMPLOYEE'.
1. QUERY:
OUTPUT:
2. QUERY:
OUTPUT:
3. QUERY:
OUTPUT:
4.QUERY:
OUTPUT:
5. QUERY:
OUTPUT:
Ex.no.19 Queries Set 4 (Group by , Order By)
Consider the following ‘stock’ table to answer the queries:
Itemno item dcode qty price stockdate
S005 Ballpen 102 100 10 2018-04-22
S003 Gel Pen 101 150 15 2018-03-18
S002 Pencil 102 125 5 2018-02-25
S006 Eraser 101 200 3 2018-01-12
S001 Sharpner 103 110 5 2018-06-11
S004 Compass 102 60 25 2018-05-10
S009 A4 Papers 102 160 5 2018-07-15
1. Display all the items in the ascending order of stockdate.
2. Display number of items,total price for each dealer individually as per dcode from stock.
3. Display all the items in descending orders of itemnames.
4. Display maximum price of items for each dealer individually as per dcode from stock which has
maximum price more than 10.
5. Display the sum of quantity for each dcode from stock which has price between 10 to 30.
1.QUERY:
OUTPUT:
2.QUERY:
OUTPUT:
3.QUERY:
OUTPUT:
4.QUERY:
OUTPUT:
5.QUERY:
OUTPUT:
Queries Set 5 (Based on Functions)
1. Write a query to display cube of 5.
2. Write a query to display the number 563.854741 rounding off to the next hnudred.
3. Write a query to display “put” from the word “Computer”.
4. Write a query to display today’s date into DD.MM.YYYY format.
5. Write a query to display ‘DIA’ from the word “MEDIA”.
6. Write a query to display moviename – type from the table movie.
7. Write a query to display first four digits of productioncost.
8. Write a query to display last four digits of businesscost.
9. Write a query to display weekday of release dates.
10. Write a query to display dayname on which movies are going to be released.
1.QUERY:
OUTPUT:
2.QUERY:
OUTPUT:
3.QUERY:
OUTPUT:
4.QUERY:
OUTPUT:
5.QUERY:
OUTPUT:
6.QUERY:
OUTPUT:
7.QUERY:
OUTPUT:
8.QUERY:
OUTPUT:
9.QUERY:
OUTPUT:
10.QUERY:
OUTPUT:
SQL Database Connectivity Programs
1. Write a MySQL connectivity program in Python to
o Create a database school
o Create a table students with the specifications – ROLLNO integer, STNAME
character(10) in MySQL and perform the following operations:
Insert two records in it
Display the contents of the table
2. Perform all the operations with reference to table ‘students’ through MySQL-Python
connectivity.
1. Insert Record 2. Update Record 3. Delete Record 4. Display Record 5. Exit
3. Write a python program that display first 8 rows fetched from student table of MySQl database
student_dbl
4. Write a python database connectivity program that deletes record from student table of
database that have name = Meena