Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

Mohsin Hassan

BBA IIB
BUS-19F-044
Computer Application

Assignment 02

Submitted to: Dr.Mazhar Ali Dootio


Submitted From: Mohsin Hassan
Name : Mohsin Hassan
Subject : Computer Application

Contents
Considered Scenario:...................................................................................................................................2
1.Selection of Database...............................................................................................................................2
2. Identifying the requirements for the database based on the purpose for the database and the data to
fill the database...........................................................................................................................................2
3.Create a database design based on the requirements for the database, create the physical database,
and load data into the database..................................................................................................................3
Create Database:.....................................................................................................................................3
Create Tables:..........................................................................................................................................3
Employee.............................................................................................................................................3
User.....................................................................................................................................................3
admin...................................................................................................................................................3
Customer.............................................................................................................................................5
Product................................................................................................................................................5
Supplier...............................................................................................................................................5
Order Detail.........................................................................................................................................5
Delivery................................................................................................................................................5
Store Record........................................................................................................................................5
Inserting Data:.........................................................................................................................................6
Admin..................................................................................................................................................6
Employee.............................................................................................................................................6
User.....................................................................................................................................................6
Product................................................................................................................................................7
Supplier...............................................................................................................................................7
4.After loading the database, carry out sample queries that would be performed on the actual database.
Show the results of the sample queries......................................................................................................7
Sample Queries:......................................................................................................................................7
Customer.............................................................................................................................................7
Order Detail.........................................................................................................................................7
Delivery................................................................................................................................................8
View Update Delete Insert Search Employee..........................................................................................8
View Update Delete Insert Search User...................................................................................................9
View Update Delete Insert Search Admins............................................................................................10
View Update Delete Insert Search Increment and Decrement Products...............................................10
View Update Delete Insert Search Supplier...........................................................................................12
View Update Delete Insert Search Delivery...........................................................................................12
View Update Delete Insert Search Order Details...................................................................................13
Considered Scenario:
Suppose, Customer will come in the market choose the stuff they want to
buy. Then come to Counter where employee of the market serving the customer
at counter will add the record of for goods which customer wanted to buy. Then
employee will generate the slip. And will ask the customer for the payment
method.

After the customer has paid the bill. He /She will be able to use the facility of
Home Delivery by Filling the form.

1.Selection of Database
Selecting SQL Server Management Studio for this database as it is

o Cost- free
o Easy to install
o Fast and efficient

2. Identifying the requirements for the database based on the purpose


for the database and the data to fill the database.

o Admin Details
o User Details
o Employee Details
o Items in list of goods with price and quantity.
o Customer Details
o Store Order Details
o Delivery System

3. Create a database design based on the requirements for the database,


create the physical database, and load data into the database.

Create Database:
 Using SQL Server Management Studio 18
create Database Store;

use Store;

Create Tables:

Employee
create table tbl_employee
(
e_id int not null,
primary key (e_id),
emp_name varchar(50) not null,
gender varchar(6) not null,
age int not null,
email varchar (49) not null,
address varchar(250) not null,
ph_no varchar(30) not null,
);

User
create table tbl_user
(
u_id int not null,
primary key (u_id),
name varchar (75) not null,
pass varchar(30) not null,
ph_no varchar(15) not null,
email varchar(49) not null,
address varchar(250) not null,
date_of_birth Date not null,
);

admin
create table tbl_admin
(
a_id int not null,
primary key (a_id),
name varchar (75) not null,
pass varchar(30) not null,
ph_no varchar(15) not null,
email varchar(49) not null,
address varchar(250) not null,
date_of_birth Date not null,
);

Customer
create table tbl_customer
(
c_id int not null,
primary key (c_id),
d_c Date not null,
time_customer Time not null,
);

Product
create table tbl_product
(
p_id int not null,
primary key (p_id),
name varchar(50) not null,
price int not null,
quantity int not null,
category varchar (17),
);

Supplier
create table tbl_supplier
(
s_id int not null,
primary key (s_id),
company_name varchar(49) not null,
address varchar(250) not null,
p_id int not null,
Foreign Key (p_id) references tbl_product(p_id),
);

Order Detail
create table tbl_order_detail
(
o_id int not null,
primary key (o_id),
c_id int not null,
Foreign Key (c_id) references tbl_customer(c_id),
p_id int not null,
Foreign Key (p_id) references tbl_product(p_id),
);

Delivery
create table tbl_delivery
(
order_id int not null,
c_id int not null,
Foreign Key (order_id) references tbl_order_detail(o_id),
d_id int not null,
primary key (d_id),
driver_name varchar(55) not null,
driver_no int not null,
);

Store Record
create table tbl_store_record
(
sr_id int not null,
primary key (sr_id),
selling int not null,
purchasing int not null,
order_id int not null,
Foreign Key (order_id) references tbl_order_detail(o_id),
supplier_id int not null,
Foreign Key (supplier_id) references tbl_supplier(s_id),
)

Inserting Data:
Admin
insert into tbl_admin values ('1','Mohsin','mohsin','mohsin123','mohsin@mail.com','House
# 96 Street # 07 Sector # 04 Naval Colony Hub River Road Karachi','1997-11-29')
insert into tbl_admin values ('2','Ahmed','ahmed','ahmed123','ahmed@mail.com','House # 17
Street # 09 Sector # 03 Naval Colony Hub River Road Karachi','1996-08-12')
insert into tbl_admin values ('3','Ali','ali','ali123','ali@mail.com','House # 06 Street
# 02 Sector # 02 Naval Colony Hub River Road Karachi','1993-01-23')
insert into tbl_admin values ('4','Baber','baber','babaer123','baber@mail.com','House #
17 Street # 12 Sector # 01 Naval Colony Hub River Road Karachi','1992-06-13')
insert into tbl_admin values ('5','Saqib','saqib','saqib123','saqib@mail.com','House # 03
Street # SR Sector # 04 Naval Colony Hub River Road Karachi','1998-05-18')

select * from tbl_admin

Employee
insert into tbl_employee values ('1','Abeera','Female',31,'abeera@mail.com','Appartment 3
Block A Karachi','+923992547')
insert into tbl_employee values ('2','Altaf','Male',25,'altaf@mail.com','Appartment 1
Block C Lahore','+9239925212')
insert into tbl_employee values ('3','Fatima','Female',18,'fatima@mail.com','Appartment
33 Block F Karachi','+923112333')
insert into tbl_employee values ('4','Shams','Male',21,'shams@mail.com','Appartment 12
Block H Karachi','+9239922343')
Select * from tbl_employee

User
insert into tbl_user values ('1','anas','anas123','+927111254','anas@mail.com','H 12 St 9
Naval Karachi','1991-10-10')
insert into tbl_user values
('2','ammar','ammar123','+928112548','ammar@mail.com','Appartment 3 Block B
Karachi','1993-10-31')
insert into tbl_user values ('3','noman','noman123','+924855512','noman@mail.com','Sec 9
St 3 H 1 Karachi','1889-03-28')
select * from tbl_user

Product
insert into tbl_product values ('1','Bloody HeadPhone 4','4000','5','Gaming')
insert into tbl_product values ('3','Cricket Bat Large','1000','50','Sports Goods')
insert into tbl_product values ('2','Need For Speed Collection','50','100','Gaming')
select * from tbl_product

Supplier
insert into tbl_product values ('1','Bloody HeadPhone 4','4000','5','Gaming')
insert into tbl_product values ('3','Cricket Bat Large','1000','50','Sports Goods')
insert into tbl_product values ('2','Need For Speed Collection','50','100','Gaming')
select * from tbl_product

4.After loading the database, carry out sample queries that would be
performed on the actual database. Show the results of the sample
queries.

Sample Queries:
Customer
insert into tbl_customer values ('1','2020-Aug-05','13:10')

select * from tbl_customer


Order Detail

insert into tbl_order_detail values ('1','1','2')


select * from tbl_order_detail

Delivery
insert into tbl_delivery values ('1','1','1','Ishtiaq','5')
select * from tbl_delivery

View Update Delete Insert Search Employee

-----------------Show Employees
create procedure pro_show_employees
AS
Select * from employees
Go
--
exec pro_show_employees

----------------Delete Employees

create proc pro_delete_employees


@Id int
AS
delete from employees where Id=@Id
Go
--
exec pro_delete_employees 1

----------------Insert Employees

create proc pro_insert_employees


@Name varchar(50),@Gender varchar(10),@Email varchar(50),@Address
varchar(250),@Phonenumber varchar(20),@DateOfBirth Date,@Salary int
AS
insert into employees values
(@Name,@Gender,@Email,@Address,@Phonenumber,@DateOfBirth,@Salary)
Go
--
----------------Update Employees
create proc pro_update_employees
@Id int,@Name varchar(50),@Gender varchar(10),@Email varchar(50),@Address
varchar(250),@Phonenumber varchar(20),@DateOfBirth Date,@Salary int
AS
update employees set Name = @Name ,Gender= @Gender,Email = @Email, Address = @Address,
[Phone Number] =@Phonenumber ,[Date Of Birth]= @DateOfBirth,Salary = @Salary where Id =
@Id
Go
--

----------------Search Emloyees

create proc pro_search_employees


@Name varchar(50)
As
Select * from employees where Name Like '%'+@Name+'%'
Go
--
EXEC pro_search_employees 'No'

View Update Delete Insert Search User


-----------------Show users

create procedure pro_show_users


AS
Select * from users
--
exec pro_show_users

----------------Delete Users

create proc pro_delete_users


@Id int
AS
delete from users where Id=@Id
Go
--
exec pro_delete_users 2

----------------Insert Users

create proc pro_insert_users


@Name varchar(50),@UserName varchar(50),@Password varchar(50),@Email varchar(50),@Address
varchar(250),@DateOfBirth Date
AS
insert into users values (@Name,@UserName,@Password,@Email,@Address,@DateOfBirth)
Go
--

----------------update Users

create proc pro_update_users


@Id int, @Name varchar(50),@UserName varchar(50),@Password varchar(50),@Email
varchar(50),@Address varchar(250),@DateOfBirth Date
AS
update users set Name = @Name ,[User Name] = @UserName, Password = @Password, Email =
@Email, Address = @Address ,[Date Of Birth]= @DateOfBirth where Id = @Id
Go
--

----------------Search Users
create proc pro_search_users
@Name varchar(50)
As
Select * from users where Name Like '%'+@Name+'%'
Go
exec pro_search_users 'Write Name Here To Search'

View Update Delete Insert Search Admins

-----------------Show admin

create procedure pro_show_admins


AS
Select * from admins
--
exec pro_show_admins

----------------Delete Admin

create proc pro_delete_admins


@Id int
AS
delete from admins where Id=@Id
Go
--
exec pro_delete_admins 2

----------------Insert Admin

create proc pro_insert_admins


@Name varchar(50),@UserName varchar(50),@Password varchar(50),@Email varchar(50),@Address
varchar(250),@DateOfBirth Date
AS
insert into admins values (@Name,@UserName,@Password,@Email,@Address,@DateOfBirth)
Go
--

----------------update Admin

create proc pro_update_admins


@Id int, @Name varchar(50),@UserName varchar(50),@Password varchar(50),@Email
varchar(50),@Address varchar(250),@DateOfBirth Date
AS
update admins set Name = @Name ,[User Name] = @UserName, Password = @Password, Email =
@Email, Address = @Address ,[Date Of Birth]= @DateOfBirth where Id = @Id
Go
--
----------------Search Admin
create proc pro_search_admins
@Name varchar(50)
As
Select * from admins where Name Like '%'+@Name+'%'
Go
exec pro_search_admins 'Uza'

View Update Delete Insert Search Increment and Decrement


Products

-----------------Show Products
create procedure pro_show_products
AS
Select * from products
Go
--
exec pro_show_products

----------------Delete Products

create proc pro_delete_products


@Id int
AS
delete from products where Id=@Id
Go
--
exec pro_delete_products 2

----------------Insert Products

create proc pro_insert_products


@Name varchar(50),@Quantity int,@Price int,@Weight int,@Sid int
AS
insert into products values (@Name,@Quantity,@Price,@Weight,@Sid)
Go
--
exec pro_insert_products
----------------Update Products

create proc pro_update_products


@Id int,@Name varchar(50),@Quantity int,@Price varchar(250),@Weight int,@Sid int
AS
update products set Name = @Name, Quantity=@Quantity,Price=@Price,Weight =
@Weight,Sid=@Sid where Id=@Id
Go
--
exec pro_update_products

----------------Search Products

create proc pro_search_products


@Name varchar(50)
As
Select * from products where Name Like '%'+@Name+'%'
Go
--
EXEC pro_search_products
----------------Increment Quantity
create procedure pro_decquantity_products
@Id int, @Quantity int
as
begin
Update products SET Quantity = Quantity - @Quantity where Id = @Id;
end
go
exec Pro_decquantity_products
----------------Decrement Quantity
create procedure pro_incquantity_products
@Id int, @Quantity int
as
begin
Update products SET Quantity = Quantity + @Quantity where Id = @Id;
end
go

View Update Delete Insert Search Supplier

-----------------Show Suppliers
create procedure pro_show_suppliers
AS
Select * from suppliers
Go
--
exec pro_show_suppliers

----------------Delete Suppliers

create proc pro_delete_suppliers


@Id int
AS
delete from suppliers where Id=@Id
Go
--
exec pro_delete_suppliers 2

----------------Insert Suppliers

create proc pro_insert_suppliers


@Name varchar(50),@Email varchar(50),@Address varchar(50),@Number varchar(20),@Created
Date
AS
insert into suppliers values (@Name,@Email,@Address,@Number,@Created)
Go
--
exec pro_insert_suppliers
----------------Update Suppliers
create proc pro_update_suppliers
@Id int,@Name varchar(50),@Email varchar(50),@Address varchar(50),@Number
varchar(20),@Created Date
AS
update suppliers set Name = @Name, Email =
@Email,Address=@Address,Number=@Number,Created=@Created where Id=@Id
Go
--
exec pro_update_suppliers

----------------Search Suppliers

create proc pro_search_suppliers


@Name varchar(50)
As
Select * from suppliers where Name Like '%'+@Name+'%'
Go
--
EXEC pro_search_suppliers b

View Update Delete Insert Search Delivery

-----------------Show Delivery
create procedure pro_show_delivery
AS
Select * from delivery
Go
--
exec pro_show_delivery

----------------Delete Delivery

create proc pro_delete_delivery


@Id int
AS
delete from delivery where Id=@Id
Go
--
exec pro_delete_delivery 1

----------------Insert Delivery

create proc pro_insert_delivery


@Orderid int,@Vehicleid int,@CustomerName varchar(50),@PhoneNumber varchar(20),@Address
varchar(250),@Date Date,@placeby varchar(50)
AS
insert into delivery values
(@Orderid,@Vehicleid,@CustomerName,@PhoneNumber,@Address,@Date,@placeby)
Go
--
exec pro_insert_delivery
----------------Update Delivery
create proc pro_update_delivery
@Id int,@PhoneNumber varchar(20),@Address varchar(250)
AS
update delivery set [Phone Number]=@PhoneNumber,[Address]=@Address where [Delivery
Id]=@Id
Go
--
exec pro_update_delivery

----------------Search delivery

create proc pro_search_delivery


@CustomerName varchar(50)
As
Select * from delivery where [Customer Name] Like '%'+@CustomerName+'%'
Go
--
EXEC pro_search_delivery

View Update Delete Insert Search Order Details

-----------------Show Orders
create procedure pro_show_orders
AS
Select * from orders
Go
--
exec pro_show_orders

----------------Delete Orders

create proc pro_delete_orders


@Id int
AS
delete from orders where Id=@Id
Go
--
exec pro_delete_orders

----------------Insert Orders

create proc pro_insert_orders


@CustomerName varchar(50),@Booked Date,@TotalWeight int,@TotalPrice int
AS
insert into orders values (@CustomerName,@Booked,@TotalWeight,@TotalPrice)
Go
--
exec pro_insert_orders
----------------Update Orders
create proc pro_update_Orders
@Id int,@CustomerName varchar(50),@Booked Date,@TotalWeight int,@TotalPrice int
AS
update orders set [Customer Name]= @CustomerName,Booked=@Booked,[Total
Weight]=@TotalWeight,[Total Price]=@TotalPrice where Id=@Id
Go
--
exec pro_update_Orders

----------------Search Orders

create proc pro_search_orders


@Name varchar(50)
As
Select * from orders where [Customer Name] Like '%'+@Name+'%'
Go
--
EXEC pro_search_orders

You might also like