SQL Assignment 1
SQL Assignment 1
Assignment # 1
A small IT firm designing business software for its clients wants to store and manage its data. It has
identified following entities for which, it will maintain data.
1. Clients
2. Employees
3. Departments
4. Projects
5. EmpProjectTasks *
The tables below describe attributes for each entity. Keep the table name same.
Clients
Attribute Name Attribute Type Constraint Remarks
Client_ID Integer Primary Key
Cname STRING(30) Not Null
Address STRING(30)
Email STRING(30) Unique
Phone STRING(10)
Business STRING(20) Not Null Business type of client
like Manufacturer,
Reseller, Consultant,
Professional etc.
Employees
Attribute Name Attribute Type Constraint Remarks
Empno Integer Primary Key
Ename STRING(20) Not Null
Job STRING(15)
Salary Decimal Must be positive Use CHECK constraint
to ensure salary is > 0
Deptno Integer Foreign Key Deptno as per
Departments table
Departments
Attribute Name Attribute Type Constraint Remarks
Deptno Integer Primary Key
Dname STRING(15) Not Null
Loc STRING(20)
Projects
Attribute Name Attribute Type Constraint Remarks
Project_ID Integer Primary Key
Descr STRING(30) Not Null Description of project
like ‘Accounting’ ,
‘Inventory’, ‘Payroll’
etc.
Start_Date DATE Start date of project
Planned_End_Date DATE Planned End date of
Project
Actual_End_date DATE Must be later than Actual End date of
Planned_End_Date project (Use CHECK
constraint)
Budget Decimal Must be positive Use CHECK constraint
to ensure budget is > 0
Client_ID INTEGER Foreign Key Client ID from Clients
Table
EmpProjectTasks
Attribute Name Attribute Type Constraint Remarks
Project_ID Integer Primary Key, Foreign Key Composite primary key
Empno INTEGER Primary Key, Foreign Key and foreign keys
referring Projects and
Employees table
Start_Date DATE Start date when
employee begins task
on this project
End_Date DATE End date when
employee finishes task
on this project
Task STRING(25) Not Null Task performed
by employee like
designing, coding,
review, testing etc.
Status STRING(15) Not Null Status of task like
‘in progress’,
‘complete’,’cancelled’
Clients
Client ID Cname AddresS Email Phone Business
Employees
Empno Ename Job Salary Dept No
Departments
Projects
EmpProjectTasks
1. Create the Clients table using the information provided above. Once tables are ready, fill in the given
data of this table.
2. Create the Departments table using the information provided above. Once tables are ready, fill in the
given data of this table.
3. Create the Employees table using the information provided above. Once tables are ready, fill in the
given data of this table.
4. Create the Projects table using the information provided above. Once tables are ready, fill in the given
data of this table.
5. Create the EmpProjectTasks table using the information provided above. Once tables are ready, fill in
the given data of this table.
6. Display customer details with business as ‘Consultant’.
7. Display employee details who are not ‘Developers’.
8. Display project details with budget > 100000.
9. Display details of project that are already finished.
10. Display employee names beginning with ‘M’.
11. Display employee names ending with ‘a’.
12. Display the task that is ‘In Progress’.
13. Display details of departments located in Pune.
14. Display employee name and salary in descending order of salary.
15. Display tasks in ascending order of end date.
16. Display distinct jobs from Employees table.
17. Display employee name, salary and bonus calculated as 25% of salary.
MS SQL Server
Assignment # 1
Topic: Assignment 1 Submitted By:Nikhil
1.Create the Clients table using the information provided above. Once tables are ready, fill in the given data of
this table.
ADDRESS VARCHAR(30),
PHONE VARCHAR(10),
);
'Man ufacturing');
2.Create the Departments table using the information provided above. Once tables are ready, fill in the given data
of this table.
ANS -
CREATE TABLE acroschema_17.DEPARTMENTS(
LOC VARCHAR(20));
3.Create the Employees table using the information provided above. Once tables are ready, fill in the given data of
this table
JOB VARCHAR(15),
DEPTNO INT );
values(7001,'Sandeep','Analyst',25000,10);
values(7002,'Rajesh','Designer',30000,10);
values(7003,'Madhav','Developer',40000,20);
values(7004,'Manoj','Developer',40000,20);
Insert into acroschema_17.EMPLOYEES (EMPNO,ENAME,JOB,SALARY,DEPTNO)
values(7005,'Abhay','Designer',35000,10);
values (7006,'Uma','Tester',30000,30);
values (7008,'Priya','Tester',35000,30);
values(7009,'Nutan','Developer',45000,20);
values (7010,'Smita','Analyst',20000,10);
values(7011,'Anand','Project Mgr',65000,10);
4.Create the Projects table using the information provided above. Once tables are ready, fill in the given data of
this table.
START_DATE DATE,
PLANNED_END_DATE DATE,
ACTUAL_END_DATE DATE,
CLIENT_ID int );
values(401,'Inventory','01-APR-2011','01-OCT-2011','31-OCT- 11',150000,1001);
values(402,'Accounting','01-AUG-2011','01-JAN-2012',null,500000,1002);
values(403,'Payroll','01-OCT-2011','31-DEC-2011',null,75000,1003);
5.Create the EmpProjectTasks table using the information provided above. Once tables are ready, fill in the given
data of this table.
EMPNO int ,
START_DATE DATE,
END_DATE DATE,
PRIMARY KEY(PROJECT_ID,EMPNO));
values (401,7003,'01-JUN-2011','15-JUL-2011','Coding','Completed');
values (401,7004,'18-JUL-2011','01-SEP-2011','Coding','Completed');
values (401,7006,'03-SEP-2011','15-SEP-2011','Testing','Completed');
values (401,7008,'06-OCT-2011','16-OCT-2011','Testing','Completed');
values (401,7007,'06-OCT-2011','22-OCT-2011','Documentation','Completed');