0% found this document useful (0 votes)
17 views6 pages

SQL Assignment 1

d <- read.csv("https://www.key2stats.com/Indian_Startup_Funding_1588_1.csv"

Uploaded by

Saurabh Bhosale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views6 pages

SQL Assignment 1

d <- read.csv("https://www.key2stats.com/Indian_Startup_Funding_1588_1.csv"

Uploaded by

Saurabh Bhosale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

MS SQL Server

Assignment # 1

Topic: Tables, Constraint, Identity, Select Time: 2 Hr

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 Composite primary
Key
key and foreign keys
Empno INTEGER Primary Key, Foreign
Key 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 Cname AddresS Email Phone Business
ID
1001 ACME Utilities Noida [email protected] 95678800 Manufacturi
m 32 ng
1002 Trackon Mumbai [email protected] 87342100 Consultant
Consultants m 90
1003 MoneySaver Kolkata [email protected] 77998866 Reseller
Distributors om 55
1004 Lawful Corp Chennai [email protected] 92103422 Professional
19
Employees
Empno Ename Job Salary Dept No

7001 Sandeep Analyst 25000 10

7002 Rajesh Designer 30000 10

7003 Madhav Developer 40000 20

7004 Manoj Developer 40000 20

7005 Abhay Designer 35000 10

7006 Uma Tester 30000 30

7007 Gita Tech.Writer 30000 40

7008 Priya Tester 35000 30

7009 Nutan Developer 450 20


00
7010 Smita Analyst 200 10
00
7011 Anand Project 650 10
Mgr 00

Departments

Deptn Dname Loc


o
10 Design Pune
20 Development Pune
30 Testing Mumba
i
40 Document Mumba
i

Projects

Project_ Descr Start_Date Planned_End_Da Actual_End_da Budge Client_I


ID te te t D
401 Inventory 01-Apr-2011 01-Oct-2011 31-Oct-2011 15000 1001
0
402 Accounting 01-Aug- 01-Jan-2012 50000 1002
2011 0
403 Payroll 01-Oct-2011 31-Dec-2011 7500 1003
0
404 Contact 01-Nov- 31-Dec-2011 5000 1004
Mgmt 2011 0
EmpProjectTasks

Project_I Empn Start_Date End_DaT Task Status


D o e
401 7001 01-Apr-2011 20-Apr- System Analysis Complete
2011 d
401 7002 21-Apr-2011 30-May- System Design Complete
2011 d
401 7003 01-Jun-2011 15-Jul- Coding Complete
2011 d
401 7004 18-Jul-2011 01-Sep- Coding Complete
2011 d
401 7006 03-Sep- 15-Sep- Testing Complete
2011 2011 d
401 7009 18-Sep- 05-Oct- Code Change Complete
2011 2011 d
401 7008 06-Oct-2011 16-Oct- Testing Complete
2011 d
401 7007 06-Oct-2011 22-Oct- Documentation Complete
2011 d
401 7011 22-Oct-2011 31-Oct- Sign off Complete
2011 d
402 7010 01-Aug- 20-Aug- System Analysis Complete
2011 2011 d
402 7002 22-Aug- 30-Sep- System Design Complete
2011 2011 d
402 7004 01-Oct-2011 Coding In
Progress
SQL Assignment # 1 – Questions

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 employee name and salary in descending order of salary.
14. Display tasks in ascending order of end date.
15. Display distinct jobs from Employees table.
16. Display employee name, salary and bonus calculated as 25% of salary.
17. Display the employee name and their corresponding department name.
18. Find the total number of employees in each department.
19. Calculate the average salary of employees for each job title.
20. Find the total budget allocated for all projects combined.
21. Count how many projects have been completed for each client.
22. Find the maximum salary for employees in the Development department.
23. List all the projects along with the names of the clients using a join between Projects and
Clients tables.
24. Show all the employees and their corresponding project descriptions where the project
status is 'In Progress'.
25. List all the employees along with their department names and the projects they have been
assigned to.
26. List the employees who worked on more than one project using a HAVING clause.

You might also like