You are on page 1of 5

THE SUPERIOR UNIVERSITY LAHORE

Assignment no 2
) Semester: 4th Section: A,B, C Session:

Faculty of Computer Science and Information Technology QCH:


Subject: Database System Marks Obtained:
Total Marks: 30

Name: Amna Naeem______


Instructions:
Roll No: __bsem-f21-135______________
1. No cutting or overwriting is allowed.
2. Use of mobile phone is strictly prohibited.
Date: _3,March,2023__________________
3. No extra time will be given.
Time Allowed: Min.
Question # Sub-Question CLO # Domain and BT Level Total Marks
1 1 C2 8
2 3 C4 16
3 3 C4 6

Question 1: Consider the following Statement and Draw the Entity-Relationship model (ERD) by
showing all attributes, identifiers, relationships, Cardinalities and Modalities. Provide physical model to
elaborate Primary keys, Unique Keys and Foreign keys.

A local social services organization acts as an agent to help female clients in a variety of ways.
The organization stores information for each client which includes their social security number,
name, address, and phone number. In addition, because some of the services provided to clients
deals with the client’s dependents, information on dependents is also stored. This includes the
dependent’s social security number, name, and age. Clients are provided services that are in turn
provided by various service providers. For example, a client might be provided job training (a
service) that is provided by an agency in state government (the actual service provider). The
organization helps match clients with available services. It is not unusual for a single client to be
eligible for several services. Information about services includes a unique service identifier and a
description. When a client is provided with a service, the date that this happens also needs to be
recorded. Information on service providers includes a unique provider identifier, name, address,
and contact phone number. It is the policy of this organization to deal with as many service
providers as possible for a single service. For example, even though they use a state agency to
provide job training, they might also use a different private agency for job training.
Relational model:

ERD:

Question 2: Consider following Relational schema and write the DDL commands (Marks
16)
 Create the necessary tables along with all attributes. Use appropriate Data types, add Primary key
constraints, make Primary Key Auto increment and add Foreign key constraints; (10 marks)
 Add CHECK constraints on email of customer and make it an unique attribute (2 marks)
 For Rental_Contract add current date and time as default date. (2 marks)
 . Use Alter Command, Add Salary of employees and apply check to set range or salary from
35000 to 150000. (2 marks)

Code:
create database amna
use amna
go

create table empolyee (


emp_id int primary key identity(1,1),
emp_name nvarchar (200) not null,
emp_lastname nvarchar (200) not null,
emp_doh DATE,
emp_phone varchar(20)check(emp_phone like '+__-________'),
)
alter table empolyee
add emp_salary money check(emp_salary between 3500 and 3400)

create table agency (


agency_id int primary key identity(1,1),
agency_name nvarchar (200) not null,
agency_phone varchar (20)check(agency_phone like '+__-________'),
agency_address nvarchar(20),
)

create table count(


count_id int primary key identity(1,1),
count_name nvarchar (200) check(count_name IN('Lahore','Karachi','Islamabad')),
count_code nvarchar (200),
)

create table c (
c_no int primary key identity(1,1),
c_name nvarchar (200),
c_model nvarchar (200) not null,
c_make int,
)

create table rent_con(


rent_con_id int primary key identity(1,1),
total_price money ,
date_of_renting date default getdate(),
date_of_returning date default getdate(),
VAT nvarchar (200),
rent_date_time date default getdate(),
)

create table custo(


custo_id int primary key identity(1,1),
first_name nvarchar (200) not null,
last_name nvarchar (200) not null,
email nvarchar (200) constraint eamil unique check(email like '___%@__%.____%'),
)

Question 3: Consider Database you develop in question 2. ( 1+1+2+2= 6 marks)


 Write DML query to update name of Employee with ID 3 and set First_name= Muhammad.
4 UPDATE employee
5 set employee first_name='Muhammad'
6 where empolyee_id = 3;

 Write a query to delete record of employee with ID not equal to 1 or 3


delete from empolyee
where empolyee_id NOT IN (1 , 3)

 Write any of 2 update commands for Agencies table


7 update Agency
8 set Agency_name = 'superior'
9 where Agency_id=1;
10
11 update Agency
12 set Agency_name = 'lums'
13 where Agency_id=3;

Good Luck

You might also like