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

Dbms Lab Work

The document provides SQL code to create a database called "hamropasal" with multiple tables, including Customers, Categories, Employees, Orders, Products, and more. It inserts sample data into each table. It then shows queries to update, select, and delete records to demonstrate CRUD operations. Finally, it provides code to create another sample database "test" with Employees and Works tables to further demonstrate CRUD operations.

Uploaded by

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

Dbms Lab Work

The document provides SQL code to create a database called "hamropasal" with multiple tables, including Customers, Categories, Employees, Orders, Products, and more. It inserts sample data into each table. It then shows queries to update, select, and delete records to demonstrate CRUD operations. Finally, it provides code to create another sample database "test" with Employees and Works tables to further demonstrate CRUD operations.

Uploaded by

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

DBMS LAB WORK:

LAB 1: TO CREATE A DATABASE hamropasal WITH MULTIPLE TABLES/ENTITIES AND


ATTRIBUTES AS SHOWN BELOW:
Database Name: hamropasal
Table: Customers

Table:
Categories

Table:
Employees

Table:
OrderDetails
Table: Orders

Table: Products

Table: Shippers

Table: Suppliers

 SQL CODE TO MAKE THIS DATABASE IS AS BELOW:


 TO CREATE A DATABASE:
CREATE DATABASE hamropasal;

 TO CREATE TABLE ‘Customers’:


CREATE TABLE Customers
(
CustomerID int not null,
CustomerName varchar(50),
ContactName varchar(50),
Address varchar(250),
City varchar(50),
PostalCode varchar(50),
Country varchar(50),
PRIMARY KEY(CustomerID)
);

 TO INSERT DATA INTO ‘CUSTOMER’ TABLE:


INSERT INTO customers VALUES(1,'Alfreds Futterkiste','Alfreds Schmidt','Obere Str.
57','Frankfurt','12209','Germany');
INSERT INTO customers VALUES(2,'Ana Trujillo Emparedados y helados','Ana Trujillo','Avda. de la
Constitución 2222','México D.F.','05021','Mexico');
INSERT INTO customers VALUES(3,'Antonio Moreno Taqueria','Antonio Moreno','Mataderos
2312','México D.F.','05023','Mexico');
INSERT INTO customers VALUES(4,'Around the Horn','Thomas Hardy','120 Hanover
Sq.','London','WA1 1DP','UK');
INSERT INTO customers VALUES(5,'Berglunds snabbkop','Christina Berglund','Brguvsvagen
8','Lulea','S-958 22','Sweden');
INSERT INTO customers VALUES(6,'Blauer See Delikatessen','Hannna Moos','Forsterstr.
57','Mannheim','68306','Germany');

 TO CREATE A TABLE ‘Categories’:


CREATE TABLE Categories(
CategoryID int not null,
CategoryName varchar(50),
Description varchar(50),
PRIMARY KEY(CategoryID)
);

 TO INSERT DATA INTO ‘Categories’ TABLE:


INSERT INTO categories VALUES(1,'Beverages','Soft drinks,coffees,teas,beers, and ales');
INSERT INTO categories VALUES(2,'Condiments','Sweet and savory sauces, relishes, spreads, and
seasonings');
INSERT INTO categories VALUES(3,'Confections ','Desserts, candies, and sweet breads');
INSERT INTO categories VALUES(4,'Dairy Products','Cheeses');

 TO CREATE A TABLE ‘Employees’:


CREATE TABLE Employees
(
EmployeeID int not null,
LastName varchar(50),
FirstName varchar(50),
BirthDate DATE,
Photo BLOB,
Notes varchar(500),
PRIMARY KEY(EmployeeID)
);

 TO INSERT DATA INTO ‘Employees’ TABLE:


INSERT INTO employees VALUES(1,'Davolio ','Nancy','1968-12-08','EmpID1.pic','Education includes a
BA in psychology from Colorrado State University. She also completed(The Art of the Cold Call).Nancy
is a member of "Toastmasters International"');

INSERT INTO employees VALUES(2,'Fuller ','Andrew','1952-02-19','EmpID2.pic','Andrew received his


BTS commercial and a Ph.D. in international marketing from the University of Dallas. He is fluent in
French and Italian and reads German. He joined the company as a sales representative, was
promoted to sales manager and was then named vice president of sales. Andrew is a member of the
Sales Management Roundtable, the Seattle Chamber of Commerce, and the Pacific Rim Importers
Association');

INSERT INTO employees VALUES(3,'Leverling ','Janet','1963-08-30','EmpID3.pic','Janet has a BS


degree in chemistry from Boston College. She has also completed a certificate program in food
retailing management. Janet was hired as a sales associate and was promoted to sales
representative');

 TO CREATE A TABLE ‘Shippers’:


CREATE TABLE Shippers
(
ShipperID int NOT null,
ShipperName varchar(50),
Phone varchar(50),
PRIMARY KEY(ShipperID)
);

 TO INSERT DATA INTO TABLE ’Shippers’:


INSERT INTO shippers VALUES(1,'Speedy Express','(503)555-9831');
INSERT INTO shippers VALUES(2,'United Package','(503)555-3199');
INSERT INTO shippers VALUES(3,'Federal Shipping','(503)555-9931');

 TO CREATE A TABLE ’Suppliers’:


CREATE TABLE Suppliers (
SupplierID int NOT null,
SupplierName varchar(50),
ContactName varchar(50),
Address varchar(50),
City varchar(50),
Postalcode varchar(50),
Country varchar(50),
Phone varchar(50),
PRIMARY KEY(SupplierID)
);

 TO INSERT DATA INTO TABLE ‘Suppliers’:


INSERT INTO suppliers VALUES(1, 'Exotic Liquid', 'Charlotte Copper', 'Gilgert St.', 'London', 'EC1 4SD',
'UK', '(171) 555-2222');
INSERT INTO suppliers VALUES(2, 'New Orleans Cajun Delights', 'Shelley Burke', 'P.O. Box 78934',
'New Orleans', '70117', 'USA', '(100) 555-4822');
INSERT INTO suppliers VALUES(3, "Grandma Kelley's Homestead", 'Regina Murphy', '707 Oxford Rd.',
'Ann Arbor', '48104', 'USA', '(313) 555-5735');
INSERT INTO suppliers VALUES(4, 'Tokyo Traders', 'Yoshi Nagase', '9-8 Sekimai Musashino-shi',
'Tokyo', '100', 'Japan', '(03) 3555-5011');
INSERT INTO suppliers VALUES(5, "Cooperative de Queso 'Las Cabras'", 'Antonio del Valle Saavedra',
'Calle del Rosal 4', 'Oviedo', '33007', 'Spain', '(98) 598 7654');

 TO CREATE A TABLE ‘Orders’:


CREATE TABLE Orders
(OrderID int NOT null,
CustomerID int,
EmployeeID int,
OrderDate date,
ShipperID int,
PRIMARY KEY(OrderID),
FOREIGN KEY(CustomerID) REFERENCES customers(CustomerID) ON DELETE CASCADE,
FOREIGN KEY(EmployeeID) REFERENCES employees(EmployeeID) ON DELETE CASCADE,
FOREIGN KEY(ShipperID) REFERENCES shippers(ShipperID) ON DELETE CASCADE);

 TO INSERT DATA INTO TABLE ‘Orders’:


INSERT INTO orders VALUES(10248,1,1,'1996-07-04',1);
INSERT INTO orders VALUES(10249,2,2,'1996-07-04',3);
INSERT INTO orders VALUES(10250,4,1,'1996-07-04',3);
INSERT INTO orders VALUES(10251,1,3,'1996-07-04',1);
INSERT INTO orders VALUES(10252,5,3,'1996-07-04',2);
INSERT INTO orders VALUES(10253,6,2,'1996-07-04',2);

 TO CREATE A TABLE ‘Products’:


CREATE TABLE Products
(
ProductID int NOT null,
ProductName varchar(50),
SupplierID int,
CategoryID int,
Unit varchar(50),
Price float,
PRIMARY KEY (ProductID),
FOREIGN KEY (SupplierID) REFERENCES suppliers(SupplierID) ON DELETE CASCADE,
FOREIGN KEY (CategoryID) REFERENCES categories(CategoryID) ON DELETE CASCADE
);

 TO INSERT DATA INTO TABLE ‘Products’:


INSERT INTO products VALUES(1,'Chais',1,1,'10 boxes x 20 bags',18);
INSERT INTO products VALUES(2,'Chang',1,1,'24-12 oz Boxes',19);
INSERT INTO products VALUES(3,'Aniseed Syrup',1,2,'12-550 ml Bottles',10);
INSERT INTO products VALUES(4,"Chef Anton's Cajun Seasoning",2,2,'48 - 6 oz jars',22);
INSERT INTO products VALUES(5,"Chef Anton's Gumbo Mix",2,2,'36 Boxes',21.35);
INSERT INTO products VALUES(6,"Gradma's Boysenberry Spread",3,2,'12-8 oz jars',25);
INSERT INTO products VALUES(7,"Uncle Bob's Organic Dried Pears",3,4,'12-1 lb pkgs.',30);

 TO CREATE A TABLE ‘OrderDetails’:


CREATE TABLE OrderDetails
(
OrderDetailID int NOT null,
OrderID int,
ProductID int,
Quantity int NOT null,
PRIMARY KEY(OrderDetailID),
FOREIGN KEY (OrderID) REFERENCES orders(OrderID) ON DELETE CASCADE,
FOREIGN KEY (ProductID) REFERENCES products(ProductID) ON DELETE CASCADE
);

 TO INSERT DATA INTO TABLE ‘OrderDetails’:


INSERT INTO orderdetails VALUES(1,10248,1,12);
INSERT INTO orderdetails VALUES(2,10248,3,10);
INSERT INTO orderdetails VALUES(3,10248,5,5);
INSERT INTO orderdetails VALUES(4,10249,2,9);
INSERT INTO orderdetails VALUES(5,10249,7,40);
INSERT INTO orderdetails VALUES(6,10250,1,10);
LAB2: TO USE OF UPDATE AND SELECT IN DATABASE ’hamropasal’

Q. Update customername to Hari Bahadur of CustomerID number 5 in customer table.


=UPDATE customers SET CustomerName='Hari Bahadur' WHERE CustomerID=5;

Q. Update categories to meat products and description to chicken,mutton,pork of categoryID 3 in


categories table
=UPDATE categories
SET CategoryName='Meat Products',Description='Chicken,Mutton,Pork'
WHERE CategoryID=3;

Q.Delete records of cutomerID 6 from customer table.


=DELETE FROM customers WHERE CustomerID=6;

Q.Increment the quantity by 10% on orderdetails table


=UPDATE orderdetails
SET Quantity=Quantity*1.1;

Q.Display all records if every proce is given a 20% raise in products table.
=SELECT ProductID,ProductName,SupplierID,CategoryID,Unit,Price*1.2
FROM products;

Q.Display all records of products whose price is greater than 20.


=SELECT * FROM products
WHERE Price>20;
LAB 3 : TO CREATE A DATABASE test WITH MULTIPLE TABLES AND ATTRIBUTES AND
USE OF CRUD OPERATION :

CREATE TABLE Employee {


Person_name varchar(50),
Street varchar(50),
City varchar(50)
};

INSERT INTO `employee`(`person_name`, `street`, `city`) VALUES ('Ram','Lindenwood','Pokhara');


INSERT INTO `employee`(`person_name`, `street`, `city`) VALUES ('Syam','Sidney','Pokhara');
INSERT INTO `employee`(`person_name`, `street`, `city`) VALUES ('Hari','Walker','Butwal');
INSERT INTO `employee`(`person_name`, `street`, `city`) VALUES ('Brian','Ridgewood','Kathmandu');
INSERT INTO `employee`(`person_name`, `street`, `city`) VALUES ('Mike','Pi','Pokhara');

CREATE TABLE Works{


Person_name varchar(50),
Bank_name varchar(50),
Salary int
};

INSERT INTO works VALUES


(‘Shyam’,’Nepal Bank’,9000),
(‘Hari,’Small Bank’,11000),
(‘Ram,’Nepal Bank’,15000),
(‘Brian,’Nabil Bank’,13000),
(‘Mike,’NMB Bank’,4000);
CREATE TABLE Bank{
Bank_name varchar(50),
City varchar(50) };

INSERT INTO `bank`(`bank_name`, `city`) VALUES ('Nepal Bank','Pokhara');


INSERT INTO `bank`(`bank_name`, `city`) VALUES ('Small Bank','Kathmandu');
INSERT INTO `bank`(`bank_name`, `city`) VALUES ('Nabil Bank','Pokhara');
INSERT INTO `bank`(`bank_name`, `city`) VALUES ('NMB Bank','Butwal');

Q. Find the sum of salary for each bank


 SELECT bank_name,SUM(salary)
FROM works GROUP BY bank_name;

Q. Display the details of the employee that works for Nepal Bank and has salary >10000.
 SELECT E.person_name,E.street,E.city
FROM employee E, works W
WHERE E.person_name=W.person_name AND W.bank_name='Nepal Bank' AND W.salary>10000;

Q. Delete ‘Small Bank’ from works table.


 DELETE FROM works
WHERE bank_name='Small Bank';

Q.2022
Q.1 Consider the relation Actress-Details and write the SQL statement fo the following queries.
i. Create the table Actress_details.

ii. Delete the data of actress whose recent release is Prem.

iii. Modify the database so that Renu's new release is "win the race" film.

iv. insert a new record on the table above table.

ANS:
i. CREATE TABLE Actress_Details
(
Players_id int not null,
Actress_name varchar(50),
Debut_year int,
Recent_release varchar(50),
Actress_fee int,
PRIMARY KEY (Players_id)
);
INSERT INTO actress_details VALUES(1, 'Renu', 2010, 'Samay', 400000);
INSERT INTO actress_details VALUES(2, 'Sita', 2022, 'Radha', 300000);
INSERT INTO actress_details VALUES(3, 'Geeta', 2001, 'Mato', 600000);
INSERT INTO actress_details VALUES(4, 'Amita', 1990, 'Man', 700000);
INSERT INTO actress_details VALUES(5, 'Karishma', 1989, 'Prem', 100000);

ii. DELETE FROM actress_details


WHERE Recent_release='Prem';

iii. UPDATE actress_details SET Recent_release='Win the race'


WHERE Actress_name='Renu';

iv. INSERT INTO actress_details VALUES(6,'Priya', 2004, 'Drishya', 500000);

You might also like