MYSQL Lab First 6 Questions
MYSQL Lab First 6 Questions
AIM
Create a table Student with the following fields and insert at least 5 records into the table except for
the column Total. Roll Number Integer Primary key, Name Varchar (25), Batch Varchar (15), Mark1
Integer, Mark2 Integer, Mark3 Integer, Total Integer
a) Update the column Total with the sum of Mark1, Mark2 and Mark3.
b) List the details of students in Commerce batch.
c) Display the name and total marks of students who are failed (Total less than 90).
d) Display the name of students in alphabetical order and in batch based
MYSQL QUERIES
CREATE DATABASE MYSQLLAB1;
USE MYSQLLAB1;
CREATE TABLE STUDENT( ROLL_NUMBER INT NOT NULL PRIMARY KEY, STUD_NAME
VARCHAR(25), BATCH VARCHAR(25), MARK1 INT , MARK2 INT, MARK3 INT , TOTAL
INT);
DESC STUDENTS;
EMPLOYEE TABLE
AIM
Create a table employee with the following fields and insert at least 5 records into the table except the
column Gross pay and DA. Emp code Integer Primary key, Emp name Varchar (20), Designation
Varchar (25), Department Varchar (25), Basic Decimal (10,2) DA Decimal (10,2), Gross pay Decimal
(10,2)
a) Update DA with 75% of Basic.
b) Display the details of employees in Purchase, Sales and HR departments.
c) Update the Gross pay with the sum of Basic and DA.
d) Display the details of employee with gross pay below 20000
MYSQL QUERIES
CREATE DATABASE MYSQLLAB2;
USE MYSQLLAB2;
CREATE TABLE EMPLOYEE(EMP_CODE INT PRIMARY KEY,EMP_NAME
VARCHAR(20),DESIGNATION VARCHAR(25),DEPARTMENT VARCHAR(25),BASIC
DEC(10,2),DA DEC(10,2),GROSS_PAY DEC(10,2));
STOCK TABLE
AIM
Create a table Stock, which stores daily sales of items in a shop, with the following fields and insert at
least 5 records into the table. Item code Integer Primary key, Item name Varchar (20) Manufacturer
Code Varchar (5), Qty Integer, Unit Price Decimal (10,2)
a) Display the item name with stock zero.
b) Display the number of items manufactured by the same manufacturer
c) Display the highest price and lowest quantity in the stock
d) Increase the unit price of all items by 10%
MYSQL QUERIES
BANK TABLE
AIM
Create a table Bank with the following fields and insert at least 5 records into the table. Acc_No
Integer Primary key Acc_Name Varchar (20) Branch_Name Varchar (25) Acc_ Type Varchar (10)
Amount Decimal (10,2)
a. Display the branch-wise details of account holders in the ascending order of the amount.
b. Insert a new column named Minimum_Amount into the table with default value 1000.
c. Update the Minimum_Amount column with the value 500 for the customers in branches other than
Alappuzha and Malappuram.
d. Find the number of customers who do not have the minimum amount 1000.
e. Remove the details of SB accounts from Thiruvananthapuram branch who have zero (0) balance in
their account.
MYSQL QUERIES
CREATE DATABASE MYSQLLAB4;
USE MYSQLLAB4;
CREATE TABLE Bank ( Acc_No INT PRIMARY KEY, Acc_Name VARCHAR (20), Branch_Name
VARCHAR(25), Acc_Type VARCHAR(10), Amount DEC(10,2) );
(b) ALTER TABLE Bank ADD COLUMN Minimum_Amount DEC(10,2) DEFAULT 1000;
(c) UPDATE Bank SET Minimum_Amount = 500 WHERE Branch_Name NOT IN
(“Alappuzha” , “Malappuram”);
(e)
DELETE FROM Bank WHERE Acc_Type =”SB” AND Branch_Name=”Thiruvananthapuram” AND
Amount<=0
BOOKS TABLE
AIM
Create a table Book with the following fields and insert at least 5 records into the table. Book_ID
Integer Primary key Book_Name Varchar (20) Author_Name Varchar (25) Pub_Name Varchar (25)
Price Decimal (10,2)
a. Create a view containing the details of books published by SCERT.
b. Display the average price of books published by each publisher.
c. Display the details of book with the highest price.
d. Display the publisher and number of books of each publisher in the descending order of the count.
e. Display the title, current price and the price after a discount of 10% in the alphabetical order of
book title.
MYSQL QUERIES
CREATE DATABASE MYSQLLAB5;
USE MYSQLLAB5;
CREATE TABLE BOOK ( BOOK_ID INT PRIMARY KEY, BOOK_NAME VARCHAR (20),
AUTHOR_NAME VARCHAR(25), PUB_NAME VARCHAR(25), PRICE DEC(10,2) );
INSERT INTO BOOK VALUES (1, “AGNICHIRAKUKAL”, “A.P.J ABDUL KALAM”, “DC
BOOKS”,157);
INSERT INTO BOOK VALUES (2, “COMPUTER SCIENCE”, “TEAM OF TEACHERS”,
“SCERT”,100);
INSERT INTO BOOK VALUES (3, “AARACHAR”,”MEERA.K.R”, “DC BOOKS”,370);
INSERT INTO BOOK VALUES (4, “RANDAMOOZHAM”, “M.T VASUDEVAN NAIR”,
“CURRENT BOOKS”,249);
INSERT INTO BOOK VALUES (5, “COMPUTER APPLICATION”, “GOVT OF KERALA”,
“SCERT”,120);
CREATE VIEW ScertView AS SELECT * FROM Book WHERE Pub_Name =”SCERT”;
SELECT * FROM ScertView;
T20
No Name Team
101 Rahul India
102 Virat India
103 Rohit India
104 Maxwel Australia
105 Williamson New Zealand
106 Miller South Africa
107 Pat Cummins Australia
MYSQL QUERIES
CREATE DATABASE MYSQLLAB6;
USE MYSQLLAB6;
CREATE TABLE ODI ( NO INT, NAME VARCHAR(25),TEAM VARCHAR(25));
INSERT INTO ODI (No, Name, Team) VALUES (1, 'Sachin', 'India'),(2, 'Virat', 'India'),(3,
'Rohit', 'India'),(4, 'Maxwel', 'Australia'),(5, 'Williamson', 'New Zealand'),(6, 'AB de Villiers',
'South Africa'),(7, 'Warner', 'Australia');
CREATE TABLE T20 (No INT, Name VARCHAR (25), Team VARCHAR (25));
INSERT INTO t20 (No, Name, Team) VALUES(101, 'Rahul', 'India'),(102, 'Virat', 'India'),(103,
'Rohit', 'India'),(104, 'Maxwel', 'Australia'),(105, 'Williamson', 'New Zealand'),(106, 'Miller', 'South
Africa'),(107, 'Pat Cummins', 'Australia');
a) SELECT NAME FROM ODI UNION SELECT NAME FROM T20;
c) SELECT NAME FROM ODI WHERE NAME NOT IN (SELECT NAME FROM
T20);
d) SELECT NAME FROM T20 WHERE NAME NOT IN (SELECT NAME FROM
ODI);