0% found this document useful (0 votes)
64 views27 pages

Ism Lab Edit RS

Here are the steps to connect MySQL server through XAMPP: 1. Open command prompt and navigate to the bin folder inside MySQL installation directory using cd commands. 2. Type 'mysql -u root -p' and hit enter. 3. You will be prompted to enter the root password. Enter the MySQL root password you set during XAMPP installation. 4. Hit enter and you will be connected to the MySQL command prompt to run queries. 5. To view the list of databases, type 'show databases' and hit enter. 6. To switch to a particular database, type 'use database_name' and hit enter. 7. You can now run queries on

Uploaded by

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

Ism Lab Edit RS

Here are the steps to connect MySQL server through XAMPP: 1. Open command prompt and navigate to the bin folder inside MySQL installation directory using cd commands. 2. Type 'mysql -u root -p' and hit enter. 3. You will be prompted to enter the root password. Enter the MySQL root password you set during XAMPP installation. 4. Hit enter and you will be connected to the MySQL command prompt to run queries. 5. To view the list of databases, type 'show databases' and hit enter. 6. To switch to a particular database, type 'use database_name' and hit enter. 7. You can now run queries on

Uploaded by

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

INFORMATION SYSTEM MANAGEMENT LAB

PRACTICAL FILE

B. COM (H)- 307


Submitted in partial fulfillment of requirement of
Bachelor of Commerce (Hons.)

B. Com(H)-V Semester (Morning)


Batch 2018-2021

Submitted to: Submitted By:


Ms. Seema Agarwal WRITE YOUR
NAME Joint Registrar
02814188818

JAGANNATH INTERNATIONAL MANAGEMENT


SCHOOL KALKAJI

1
2
Q5. Write Steps to connect MYSQL server through XAMPP.

STEPS TO OPEN MYSQL COMMAND PROMPT

1. GO TO START>>RUN----TYPE CMD AND RUN AS ADMINISTRATOR

2. AT THE COMMAND PROMPT TYPE -

C\WINDOWS\SYSTEM32>CD\

C:\>Dir x*

C:\>CD XAMPP

C:\XAMPP>CD MYSQL

C:\XAMPP\MYSQL>CD BIN

C:\XAMPP\MYSQL\BIN>mysql –u root –p –h 127.0.0.1

Press Enter

3. GO TO START>>RUN----TYPE XAMPP

SELECT XAMPP CONTROL PANEL

4. START MYSQL

5. Come back to Command prompt

Press enter at Password option

6. Now you get full Command prompt to start commands.

3
SCREENSHOTS :

4
Q6. Create a Database EMP . Use EMP . Create a Table
STUDENT with 4 Columns – S_ID, S_name, S_email and
course.

SYNTAX OF COMMAND:

1. CREATE DATABASE databasename;

2. CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,.... );

MYSQL STATEMENTS:
Mysql> create database EMP;
Mysql>use EMP;
Mysql>crate table STUDENT (S_ID int, S_Name varchar(30), S_Email varchar(30),
Course varchar(10));
Mysql> _

SCREENSHOT :

5
Q7. Insert 10 records in the table STUDENT. The first name
should be your name in the table.

SYNTAX OF COMMAND:
1. INSERT INTO table_name
VALUES (value1, value2, value3, ...);

MYSQL STATEMENTS:
Mysql> insert into STUDENT values ( 001, “WRITE YOUR NAME”, “WRITE YOUR
NAMEWRITE YOUR [email protected]”, “BCOM”);
Mysql> insert into STUDENT values ( 002, “Soham Ghosh”,
[email protected]”, “BBA”);
Mysql> insert into STUDENT values ( 003, “Sidhant Sharma”, “Sidhantsharma
@gmail.com”, “BBA”);
Mysql> insert into STUDENT values ( 004, “arushi Chopra”,
[email protected]”, “BCOM”);
Mysql> insert into STUDENT values ( 005, “Sankalp Arya”,
[email protected]”, “BBA”);
Mysql> insert into STUDENT values ( 006, “Nitya Taneja”,
[email protected]”, “BCOM”);
Mysql> insert into STUDENT values ( 007, “Paavni Grover”,
[email protected]”, “BCOM”);
Mysql> insert into STUDENT values ( 008, “Gaurav Rawat”,
[email protected]”, “BCOM”);
Mysql> insert into STUDENT values ( 009, “Rashika ”, “[email protected]”,
“BBA”);
Mysql> insert into STUDENT values ( 0010, “Naman”, “[email protected]”,
“BCOM”);
Mysql> select * from STUDENT;
Mysql> _

6
Q8. Write a query in SQL to select only S_Name, and
S_Email of the STUDENT. Also write a query to display
names of students in course BBA.

SYNTAX OF COMMAND:
1. SELECT column1, column2, ...
FROM table_name;

MYSQL STATEMENT:
Mysql> select S_Name, S_Email from STUDENT;
Mysql> select S_Name from STUDENT where Course= “BBA”;
Mysql> _

Q9. Write a query in SQL to select only S_name in


descending and ascending order .

SYNTAX OF COMMAND:

1. SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC/DESC;

MYSQL STATEMENTS:
Mysql> select S_Name from STUDENT order by S_Name desc;
Mysql> select S_Name from STUDENT order by S_Name asc;

7
Q10. Change the name of the student with S_ID =2 as
Parth.

SYNTAX OF COMMAND:
1. UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

MYSQL STATEMENTS:
Mysql> update STUDENT set S_Name= “Parth” where S_ID=2;
Mysql> select * from STUDENT;
Mysql> _

Q11. A) Add a column “Salary” and assign salary to each


student. Show query to display salary in ascending order.

SYNTAX OF COMMAND:

1. ALTER TABLE table_name
ADD column_name datatype;

2. UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

3. SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC/DESC;

MYSQL STATEMENTS :
Mysql> alter table STUDENT add S_Salary decimal;
Mysql> update STUDENT set S_Salary=25000 where S_ID=1;
Mysql> update STUDENT set S_Salary=21000 where S_ID=2;
Mysql> update STUDENT set S_Salary=24500 where S_ID=3;

8
Mysql> update STUDENT set S_Salary=27000 where S_ID=4;
Mysql> update STUDENT set S_Salary=29000 where S_ID=5;
Mysql> update STUDENT set S_Salary=28000 where S_ID=6;
Mysql> update STUDENT set S_Salary=22500 where S_ID=7;
Mysql> update STUDENT set S_Salary=30000 where S_ID=8;
Mysql> update STUDENT set S_Salary=32000 where S_ID=9;
Mysql> update STUDENT set S_Salary=26000 where S_ID=10;
Mysql> select * from STUDENT;
Mysql> select S_Salary from STUDENT order by S_Salary asc;
Mysql> _

9
Q11. B) Increase salary of all students of BCOM by
Rs10000.

SYNTAX OF COMMAND:
1. UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

MYSQL STATEMENTS:
Mysql> update STUDENT set S_Salary=S_Salary+10000 where course=”BCOM”;
Mysql> select * from STUDENT;
Mysql> _

Q12. Write a query to find the maximum , Minimum and


average salary.

SYNTAX OF COMMAND:
1. SELECT MAX(column_name)
FROM table_name
WHERE condition;

2. SELECT MIN(column_name)
FROM table_name
WHERE condition;

3. SELECT AVG(column_name)
FROM table_name
WHERE condition;

MYSQL STATEMENTS:
Mysql> select max(S_Salary) from STUDENT;
Mysql> select min(S_Salary) from STUDENT;
Mysql> select avg(S_Salary) from STUDENT;

10
Q13. Write a query to find the name of the student having
maximum salary.

SYNTAX OF COMMAND:
1. SELECT column1, column2, ...
FROM table_name
WHERE condition;

MYSQL STATEMENTS:
Mysql> select S_Name, S_Salary from STUDENT where(S_Salary=(select
max(S_Salary) from STUDENT));

Q14. Write a query to find the count of students , count of


students in BBA , count of students in BCOM.

SYNTAX OF COMMAND:
1. SELECT COUNT(column_name)
FROM table_name
WHERE condition;

MYSQL STATEMENTS:
Mysql> select count (S_Name) from STUDENT;
Mysql> select count (S_Name) from STUDENT where Course=”BBA”;
Mysql> select count (S_Name) from STUDENT where Course=”BCOM”;

11
Q15. A)Delete the record with S_ID= 6,8,9 using a single
query.

SYNTAX OF COMMAND:
1. DELETE FROM table_name WHERE condition;

MYSQL STATEMENTS:
Mysql> delete from STUDENT where S_ID=6 or S_ID=8 or S_ID=9;
Mysql> select * from STUDENT;

Q15 B) Delete all the records from the table STUDENT for
students in BBA course using a single query.

SYNTAX OF COMMAND:
1. DELETE FROM table_name WHERE condition;

MYSQL STATEMENTS:
Mysql> delete from STUDENT where course=”BBA”;
Mysql> select * from STUDENT;

12
Q16. Add column Temp decimal, Delete the column Temp
from the table STUDENT.

SYNTAX OF COMMAND:
1. ALTER TABLE table_name
ADD column_name datatype;

2. ALTER TABLE table_name
DROP COLUMN column_name;

MYSQL STATEMENTS :
Mysql> alter table STUDENT add Temp decimal;
Mysql> select * from STUDENT;
Mysql> alter table STUDENT drop Temp;

Q 17. Delete the table STUDENT.

SYNTAX OF COMMAND:
1. DROP TABLE table_name;

MYSQL STATEMENTS:
Mysql> drop table STUDENT;

13
Q18. A) Create a table for Bank_detail with ( Acc_No
integer, Acc_type char, C_name varchar(50), balance
decimal) .Make Primary Key as their account number.

SYNTAX OF COMMAND:
1. CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,....);

2. ALTER TABLE Persons
ADD PRIMARY KEY (ID);

MYSQL STATEMENTS:
Mysql> create table Bank_Details (Acc_No int, Acc_Type char, C_Name
varchar(30), Balance decimal);
Mysql> alter table Bank_Details add primary key(Acc_No);

Q18. B) Add primary key in existing table STUDENT.

SYNTAX OF COMMAND:
1. ALTER TABLE Persons
ADD PRIMARY KEY (ID);

MYSQL STATEMENTS:
Mysql> select * from student;
Mysql> alter table student add primary key(S_ID);

14
Q19.Insert the database for 10 customers in Bank_detail.

SYNTAX OF COMMAND:
1. INSERT INTO table_name
VALUES (value1, value2, value3, ...);

MYSQL STATEMENTS:
Mysql> insert into Bank_Details values (500110, “C”, “Tanmay Rana”, 895000);
Mysql> insert into Bank_Details values (500112, “S”, “Samay Raina”, 650000);
Mysql> insert into Bank_Details values (500135, “S”, “WRITE YOUR NAME”,
450000);
Mysql> insert into Bank_Details values (500136, “S”, “Sanjeev Sehgal”, 1150000);
Mysql> insert into Bank_Details values (500148, “S”, “Simran Bansal”, 570000);
Mysql> insert into Bank_Details values (500171, “C”, “Anmol Kamra”, 890000);
Mysql> insert into Bank_Details values (500176, “C”, “Gaurav Kumar”, 120000);
Mysql> insert into Bank_Details values (500188, “C”, “Abhishekh Sharma”, 690000);
Mysql> insert into Bank_Details values (500189, “S”, “Vaibhav Singh”, 960000);
Mysql> insert into Bank_Details values (500199, “S”, “Rahul Bhatia”, 236000);
Mysql> select * from Bank_Details;

Q20. Show the entry for Null Entry for Customer account
number in table bank_detail.

SYNTAX OF COMMAND:
1. INSERT INTO table_name
VALUES (value1, value2, value3, ...);

MYSQL STATEMENTS:
Mysql> insert into Bank_Details values (NULL, “C”, “Sankalp Arya”, 120000);
NOTE: THE ABOVE COMMAND WILL SHOW AN ERROR AS ACCOUNT
NUMBER IS THE PRIMARY KEY OF THE TABLE AND ACCOUNT NUMBER CAN
NOT BE NULL.

15
16
Q21.Count the records where balance is greater than
Rs.6,00,000 .

SYNTAX OF COMMAND:
1. SELECT COUNT(column_name)
FROM table_name
WHERE condition;

MYSQL STATEMENTS:
Mysql> select * from bank_details;
Mysql> select count(balance) from bank_details where balance>600000;

Q22. Update the table bank_detail for the balance equal to


Rs.6,00,000 if it is less than Rs.6,00,000.

SYNTAX OF COMMAND:
1. UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

MYSQL STATEMENTS:
Mysql> update bank_details set balance=600000 where balance<600000;

17
Q23. Delete the rows from the table bank_detail where
balance is between 6,00,000 & 7,00,000.

SYNTAX OF COMMAND:
1. DELETE FROM table_name WHERE condition;

MYSQL STATEMENTS:
Mysql> delete from bank_details where Balance>600000 and balance <700000;
Mysql> select * from bank_details;

Q24. Define the following functions with examples:

Count :
The COUNT function returns the total number of values in the specified field. It works
on both numeric and non-numeric data types. All aggregate functions by default
exclude nulls values before working on the data.
COUNT() SYNTAX:
SELECT COUNT(column_name)
FROM table_name
WHERE condition;

Sum :
Returns the sum of all the values in the specified column. SUM works on
numeric fields only. Null values are excluded from the result returned.
SUM() SYNTAX:
SELECT SUM(column_name)
FROM table_name
WHERE condition;

Average :
MySQL  AVG function returns the average of the values in a specified column.
Just like the SUM function, it works only on numeric data types.

18
AVG() SYNTAX:
SELECT AVG(column_name)
FROM table_name
WHERE condition;

Max :
The MAX function is the opposite of the MIN function. It returns the largest value
from the specified table field.
MAX() SYNTAX
SELECT MAX(column_name)
FROM table_name
WHERE condition;

Min:
The MIN function returns the smallest value in the specified table field.
MIN() SYNTAX:
SELECT MIN(column_name)
FROM table_name
WHERE condition;

19
Q 26. Find out different status from the orders table.
Create this table and enter 7 records with status as
CANCELLED(3), INPROCESS(1), SHIPPED (1) and
DELIVERED(2).

SYNTAX OF COMMAND:
1. CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,.....);

2. INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

3. SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country;

MYSQL STATEMENTS:
Mysql> create table orders (orderid int primary key, orderDate date, requiredDate
date, shippedDate date, status varchar(20), comments varchar(50), customerName
varchar(50));
Mysql> insert into orders values ( 5001, ‘2020/10/20’, ‘2020/10/25’, ‘2020/10/22’,
“DELIVERED”, “delivered successfully”, “WRITE YOUR NAME”);
Mysql> insert into orders values ( 5002, ‘2020/10/22’, ‘2020/10/26’, ‘2020/10/24’,
“CANCELLED”, “customer not available”, “Sameer Khurana”);
Mysql> insert into orders values ( 5003, ‘2020/10/23’, ‘2020/10/26’, ‘2020/10/25’,
“INPROCESS”, “delivery soon”, “Gurpreet Singh”);
Mysql> insert into orders values ( 5004, ‘2020/10/25’, ‘2020/10/30’, ‘2020/10/29’,
“SHIPPED”, “delivered tomorrow”, “Aman Kamra”);
Mysql> insert into orders values ( 5005, ‘2020/10/27’, ‘2020/10/29’, ‘2020/10/28’,
“DELIVERED”, “delivered successfully”, “Rohit Sharma”);
Mysql> insert into orders values ( 5006, ‘2020/10/26’, ‘2020/10/28’, ‘2020/10/27’,
“CANCELLED”, “customer not available”, “Meenu Gupta”);
Mysql> insert into orders values ( 5007, ‘2020/10/20’, ‘2020/10/23’, ‘2020/10/21’,
“CANCELLED”, “customer not available”, “Manoj thakur”);
Mysql> select * from orders;

20
Mysql> select status, count(*) from orders group by

Q 27. Show the orders recent on the top and highest


value order with customer name. Add two columns QTY &
Unit Price in the table.

SYNTAX OF COMMAND:
1. SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

2. ALTER TABLE table_name
ADD column_name datatype;

3. UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

MYSQL STATEMENTS:
Mysql> select requiredDate, CustomerName from orders order by requiredDate asc;
Mysql> alter table orders add Quantity int;
Mysql> update orders set quantity=3 where ordered=5001;
Mysql> update orders set quantity=1 where ordered=5002;
Mysql> update orders set quantity=5 where ordered=5003;

Mysql> alter table orders add Unit_Price int;


Mysql> update orders set Unit_Price=550 where ordered=5001;
Mysql> update orders set Unit_Price=799 where ordered=5002;
Mysql> update orders set Unit_Price=850 where ordered=5003;
Mysql> update orders set Unit_Price=265 where ordered=5004;
Mysql> select * from orders;
Mysql> select CustomerName, max(Quantity*Unit_Price) from orders where
((Quantity*Unit_Price)=(select max(Quantity*Unit_Price) from orders));

21
22
Q 28. SQL FOREIGN KEY Constraint.

SYNTAX OF COMMAND:
1. CREATE TABLE Persons (
    ID int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    PRIMARY KEY (ID));

2. INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

3. ALTER TABLE Orders
ADD FOREIGN KEY (PersonID) 
REFERENCES Persons(PersonID);

MYSQL STATEMENTS:
Mysql> create table persons(PersonId int primary key, LastName varchar(50),
FirstName varchar(50), Age int);
Mysql> insert into persons value(1001, “WRITE YOUR SURNAME”, “WRITE YOUR
NAME”, 20);
Mysql> insert into persons value(1002, “Sharma”, “Somesh”, 22);
Mysql> insert into persons value(1005, “Kapoor”, “Rahul”, 27);
Mysql> select * from persons;

Mysql> create table orederFkey (OrderId int primary key, OrderNumber int not nul,
PersonId int, Foreign key (personId) references persons(personId));
Mysql> insert into orederFkey values(2001, 80090,1001);
Mysql> insert into orederFkey values(2002, 80098,1001);
Mysql> insert into orederFkey values(2003, 80020,1002);
Mysql> insert into orederFkey values(2006, 80011,1005);
Mysql> select * from orederFkey;
Mysql> select * from persons;

23
24
Q29. Addition and removal of foreign Key in existing table.

SYNTAX OF COMMAND:
1. ALTER TABLE Orders
ADD FOREIGN KEY (PersonID) 
REFERENCES Persons(PersonID);

2. ALTER TABLE Orders
DROP FOREIGN KEY FK_PersonOrder;

MYSQL STATEMENTS:
Mysql> select * from oredersfkey;
Mysql> select * from persons;
Mysql> alter table oredersfkey add foreign key(personid) references
persons(personid);
Mysql> alter table oredersfkey drop foreign key;

25
Q31. Practice question on primary , foreign Key &
functions.

A). Create table Staff


STAFF_ID | FIRST_NAME | EMAIL | PHONE_NUMBER | HIRE_DATE
| JOB_ID| SALARY

B). Make STAFF_ID as primary key


C). Create Table Jobs
JOB_ID , TITLE , MIN SALARY , MAX SALARY , NO of JOBS

D). Create Foreign key in Staff table

E). Find name of Oldest staff in the company ( Hire date to be min)

F). Find monthly salary bill of the company

G). Find name of recent staff in the company

H). Find Job title of staff with Maximum salary

MYSQL STATEMENTS:
Mysql> select first_name, hire_date from staff where (hire_date=(select
min(hire_date) from staff));
Mysql> select sum(salary) from staff;
Mysql> select first_name, hire_date from staff where (hire_date=(select
max(hire_date) from staff));
Mysql> select jobs.title, staff.salary from staff, jobs where salary=(select
max(staff.salary) from staff) and jobs.job_id=staff.job_id;
Mysql> select jobs.title, staff.salary, staff.first_name from staff, jobs where
salary=(select max(staff.salary) from staff) and jobs.job_id=staff.job_id;

26
27

You might also like