0% found this document useful (0 votes)
3 views

Database Lab Report

The document outlines a series of SQL commands related to a database named 'arafat378', including the creation of tables for 'Customer', 'Person', 'Students', and 'Courses'. It demonstrates various SQL operations such as inserting data, altering tables, and querying information based on conditions like 'BETWEEN', 'IN', and 'NOT IN'. Additionally, it includes examples of aggregate functions like MIN, MAX, AVG, and COUNT, along with data retrieval techniques using SELECT statements.

Uploaded by

easin7arafat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Database Lab Report

The document outlines a series of SQL commands related to a database named 'arafat378', including the creation of tables for 'Customer', 'Person', 'Students', and 'Courses'. It demonstrates various SQL operations such as inserting data, altering tables, and querying information based on conditions like 'BETWEEN', 'IN', and 'NOT IN'. Additionally, it includes examples of aggregate functions like MIN, MAX, AVG, and COUNT, along with data retrieval techniques using SELECT statements.

Uploaded by

easin7arafat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Lab Repot

MD. Easin Arafat Section:10


ID:20234103378 Intake:52

Lab -1

CREATE DATABASE arafat378

USE arafat378;
CREATE TABLE Customer (
Customer _id int ,
Customer _name varchar (255),
Purchase _item varchar (255),
address varchar (255),
postal _code int,
phone _number varchar (15)
); USE arafat378;
INSERT INTO Customer (customer _id, customer _name, purchase _item, address, postal _code,
phone _number)
VALUES
(1, ' Adiba Mehjabin ', 'Three Piece', 'Dhanmondi', 1205, '0131745367'),
(2, 'Rafiqul Islam', 'Wallet', 'Mirpur 1', 1216, '0161745387'),
(3, 'Sanjila Islam', 'Kurti', 'Uttarkhan', 1106, '0171748367'),
(4, 'Sharifa Begum', 'Bed sheet', 'Sector 7', 1108, '0191745388'),
(5, 'Amina Begum', 'Two Piece', 'Badda', 1300, '0131745768'),
(6, 'Monowara Akter', 'Ear ring', 'Mirpur 12', 1217, '0151845366');

(Lab-4)
USE arafat378;
CREATE TABLE Person (
Person _Name varchar (100),
Person _Id int,
Address varchar (100),
Price int

);
INSERT INTO Person
(Person _Name,
Person _Id ,
Address ,
Price )
VALUES
('Easin',78,'Mirpur',50000),
('Anas',72,'Tongi',4500),
('Miel',68,'Borguna',4005),
('Sadia',70,'Dhamrai',4590),
('Ador',88,'Chadpur',4580);

Between:
USE arafat378;
SELECT * FROM Person
WHERE Price BETWEEN 10000 AND 50000;

In:
USE arafat378;

SELECT * FROM Person


WHERE Address IN ('Mirpur','Dhamrai','Chadpur');

Not In:
USE arafat378;
SELECT * FROM Person
WHERE Address NOT IN ('Mirpur','Dhamrai');

Group By:

USE arafat378;
SELECT Person _Name, COUNT(Person _Name) AS TOTAL _Person
FROM Person
GROUP BY Person_Name;
ASEC: USE arafat378;

SELECT * From Person


ORDER BY Price ASC;

DSEC:
USE arafat378;
SELECT * From Person

ORDER BY Price DESC;


2nd,3rd: USE arafat378;

SELECT * From Person


ORDER BY Price DESC
LIMIT 1 OFFSET 1 ;

USE arafat378;
SELECT * From Person
ORDER BY Price DESC
LIMIT 1 OFFSET 2 ;
Min: USE arafat378;

SELECT MIN(Price) FROM Person;

Max: USE arafat378;

SELECT MAX(Price) FROM Person;

Avg: USE arafat378;

SELECT AVG(Price) FROM Person;

Count: USE arafat378;

SELECT COUNT(*) FROM Person;


(Lab-2)

CREATE DATABASE arafat378

USE arafat378;
CREATE TABLE Customer (
Customer _id int ,
Customer _name varchar (255),
Purchase _item varchar (255),
address varchar (255),
postal _code int,
phone _number varchar (15)
); USE arafat378;
INSERT INTO Customer (customer _id, customer _name, purchase _item, address, postal _code,
phone _number)
VALUES
(1, ' Adiba Mehjabin ', 'Three Piece', 'Dhanmondi', 1205, '0131745367'),
(2, 'Rafiqul Islam', 'Wallet', 'Mirpur 1', 1216, '0161745387'),
(3, 'Sanjila Islam', 'Kurti', 'Uttarkhan', 1106, '0171748367'),

(4, 'Sharifa Begum', 'Bed sheet', 'Sector 7', 1108, '0191745388'),


(5, 'Amina Begum', 'Two Piece', 'Badda', 1300, '0131745768'),
(6, 'Monowara Akter', 'Ear ring', 'Mirpur 12', 1217, '0151845366');
1. USE arafat378;
ALTER TABLE Customer
ADD COLUMN Customer _Grade VARCHAR(10);

2. USE arafat378;
ALTER TABLE Customer
DROP COLUMN Postal _code;

3. USE arafat378;
ALTER TABLE Customer
ADD Address_details varchar(255);

4.
USE arafat378;
ALTER TABLE Customer
MODIFY COLUMN phone_number int(15);
5, UPDATE customer set PurchaseIteam='shirt' WHERE CustomerID=3;

6. ALTER TABLE customer ADD PRIMARY KEY (CustomerID);

7. ALTER TABLE customer; UPDATE customer SET CustomerGrade = 'gold' where CustomerID=1;

8. SELECT CustomerGrade FROM customer WHERE CustomerGrade='gold';

9. TRUNCATE TABLE customer;

10. DROP TABLE customer;

(Lab-3)
CREATE DATABASE arafat378

USE arafat378;
CREATE TABLE Customer (
Customer _id int ,
Customer _name varchar (255),
Purchase _item varchar (255),
address varchar (255),
postal _code int,
phone _number varchar (15),
Grade varchar(15)
);
USE arafat378;
INSERT INTO Customer (customer _id, customer _name, purchase _item, address, postal _code,
phone _number)
VALUES
(1, ' Adiba Mehjabin ', 'Three Piece', 'Dhanmondi', 1205, '0131745367',’Silver’),
(2, 'Rafiqul Islam', 'Wallet', 'Mirpur 1', 1216, '0161745387',’Silver’),
(3, 'Sanjila Islam', 'Kurti', 'Uttarkhan', 1106, '0171748367',’Gold’),

(4, 'Sharifa Begum', 'Bed sheet', 'Sector 7', 1108, '0191745388',’Plantinum’),


(5, 'Amina Begum', 'Two Piece', 'Badda', 1300, '0131745768',’Silver’),
(6, 'Monowara Akter', 'Ear ring', 'Mirpur 12', 1217, '0151845366',’Gold’);

1. SELECT * FROM Customer Grade=’Gold’;

2.SELECT * FROM Customer PurchaseItem=’Wallet’;


3.SELECT PhoneNumber FROM Customer;

4.SELECT CustomerID ,Address ,Grade FROM Customer;

5.SELECT Grade FROM Customer WHERE PurchaseItem=’Bed sheet’


AND Grade =’Silver’

6. SELECT Grade FROM Customer WHERE PostalCode=1106 AND


CustomerId=6;
7. . SELECT * FROM Customer WHERE CustomerName LIKE ‘M%’;

8. . SELECT * FROM Customer WHERE CustomerName LIKE ‘%M’;

9. . SELECT * FROM Customer WHERE CustomerName LIKE ‘ M%’;

10. . SELECT * FROM Customer WHERE CustomerName =’Sanjida


Islam’
(Lab -5)

a)

USE arafat378;

CREATE TABLE Students (

Student _ID int,

Name Varchar(100),

Age int ,

Major Varchar(100)

);

Then

USE arafat378;

CREATE TABLE Courses

Course_ID int,

Courses_Nmae Varchar (100),

Creadits int,

Instructor_ID int

);

Then

USE arafat378;

CREATE TABLE Enrolments (

Enrolment_ID int,

Student_ID int,

Course_ID int,

Semester Varchar (100),

Grade Varchar (100)


);

a).

To Fetch The name and age of students who are majoring in cs.

USE arafat378;

INSERT INTO Students (

Student_ID ,

Name ,

Age ,

Major

VALUE

(368,'Sifat',21,'Computer Science'),

(378,'Easin',70,'Operating System'),

(372,'Anas',23,'Networking'),

(388,'Ador',21,'Computer Science');

Then USE arafat378;

SELECT Name,Age FROM Students WHERE Major='Computer Science';

b).

To Retrieve Name of all Students who are enrolled in either Database System or Ai ,

d).

input:

USE arafat378;
SELECT * FROM Students WHERE Name LIKE '__j%' and Name LIKE'%n';

Output : Null

e)

Input :

USE arafat378;

ALTER TABLE Students

ADD COLUMN Phone _number Varchar(15);

SELECT * FROM Students;

You might also like