You are on page 1of 10

Mohan Aggarwal MCA - 1B

ASSIGNMENT - 4

Dep_master table -

Employee_master table-

Vendor_master table-

Material_master table-
Mohan Aggarwal MCA - 1B

Order_master table-

Query-1) Modify the structure of the Employee_master table to have primary key
constraint on the field employee_no.
Answer: Alter table Employee_master add Primary Key(Employee_no);
Desc Employee_master;
Mohan Aggarwal MCA - 1B

Query-2) Modify the structure of Order_master table to have foreign key constraint on
the field employee_no.
Answer: Alter table Order_master add Foreign Key(Employee_no) References
Employee_master(Employee_no);

Desc Order_master;

Query-3) Write a query to select the vendor_id, name, and phone of the vendor who
lives in the state of delhi.
Answer: Select Vendor_id,Vendor_name,Phone from Vendor_master Where State="delhi";

Query-4) Write a query to select the name and address of vendor whose name contain
the letter ‘A’.
Mohan Aggarwal MCA - 1B

Answer: Select Vendor_name,Address1,Address2 from Vendor_master where Vendor_name


Like '%A%';

Query-5) Write a query to count the number of vendors who fall in the state of delhi.
Answer: Select Count(Vendor_name) From Vendor_master where State="delhi";

Query-6) Write a query to select vendor_id, name and state of the vendor whose
address1 field has a ‘.’ In it.
Answer: Select Vendor_id,Vendor_name,State from Vendor_master where Address1 like
'%.%';

Query-7) Write a query to list the details of vendors who does not belong to the state of
“Uttar Pradesh” and “Rajasthan”.
Answer: Select*from Vendor_master where State!="Rajasthan" And State!="Uttar Pradesh";
Mohan Aggarwal MCA - 1B

Query-8) Write a query to list the material_id, its description and stock available for
those
whose unit price falls above 10 but less than 1000.
Answer: Select Material_id,Material_desc,Stock from Material_master where Unit_price>10
And Unit_price<1000;

Query-9) Write a query to display information of a material whose unit price is either
800 or 1000 or 900.
Answer: Select* from Material_master where (Unit_price=800 OR Unit_price=1000 OR
Unit_price=900);

Query-10) Write a query to display the information about the material values in the
stock is less than 90.
Answer: Select* from Material_master where Stock<90;

Query-11) Write a query to change the address1 of vendor to “18d rohini-9” whose
vendor_id is “v1”.
Mohan Aggarwal MCA - 1B

Answer: Update Vendor_master Set Address1="18d rohini-9" where Vendor_id="v1";


Select*from Vendor_master;

Query-12) Write a query to modify the Date of Birth to “07 August 1988” where emp_id
is e1.
Answer: Update Employee_master set Dob="1988-08-07" where Employee_no="e1";
Select * From Employee_master;

Query-13) Write a query to display the name of all employee whose commission is more
than 10% of their basic salary and falls in the category of mgr.
Answer: Select Employee_name from Employee_master where
Commission>((Basic*10)/100) And Designation="Mgr";

Query-14) Write a query to select the employee_no and name of those employees who
earn salary more than average salary of all the employees working in the organization.
Answer: Select Employee_no, Employee_name from Employee_master where Basic>(Select
Avg(Basic) from Employee_master);
Mohan Aggarwal MCA - 1B

Query-15) Write a query to select the minimum, maximum and average salary of the
employees working in organization. The heading should be smin, smax, and savg
respectively.
Answer: Select Min(Basic) As smin,Max(Basic) As smax, Avg(Basic) As savg From
Employee_master;

Query-16) Write a query to display the employee_no, name and dept_no of all
employees who are either working as manager or vp. The grouping should be
department wise, within the department it should have all manager and all vp together.
Answer: Select Employee_no,Employee_name,Dept_no from Employee_master where
Designation="mgr" Or Designation="vp" Order by Designation;

Query-17) Write a query to inform you about the number of employees who are
designates as manager.
Answer: Select *from Employee_master where Designation="mgr";

Query-18) Write a query to select name, dept_name and location of employees who are
designates as manager.
Mohan Aggarwal MCA - 1B

Answer: Select Employee_name,dept_name,dept_location from Employee_master em join


Dep_master dm where em.dept_no=dm.dept_no And Designation="mgr";

Query-19) Write a query to display the name, designation, dept_name and location who
does not work in the “delhi” office.
Answer: Select Employee_name,Dept_name,Designation,dept_location from
Employee_master em Join Dep_master dm Where em.Dept_no=dm.Dept_no And
dept_location!="delhi";

Query-20) Write a query to list the name and id of all employees in alphabetical order
of their names.
Answer: select Employee_name,Employee_no from Employee_master Order by
Employee_name Asc;

Query-21) Write a query to select the name and dob of those employees who are born
before Sep 7,1992.
Answer: Select Employee_name,Dob from Employee_master where Dob<"1992-09-07";
Mohan Aggarwal MCA - 1B

Query-22) Write a query to select the name and department of those employees who
have age between 20 and 30 years.
Answer : Select Employee_name,Dept_name from Employee_master em Join Dep_master
dm On em.dept_no=dm.dept_no Where (Year(Curdate())-Year(Dob)) Between 20 And 30;

Query-23) Write a query to select the name and basic salary of employees who have a
letter ‘l’ or ‘e’ in their names. Further modify the query list for those who does not
contain single ‘n’ in their name.
Answer: Select Employee_name,Basic from Employee_master Where Employee_name Like
"%l%" OR Employee_name Like "%e%";

Select Employee_name,Basic from Employee_master Where Employee_name Like "%l%"


OR Employee_name Like "%e%" And Employee_name Not Like "%n%";

Query-24) Write a query to list the id, name and dept_no of employees who are born in
the month of September.
Answer: Select Employee_no,Employee_name,Dept_no from Employee_master where
Month(Dob)=9;
Mohan Aggarwal MCA - 1B

You might also like