0% found this document useful (0 votes)
66 views2 pages

MySQL Commands and Database Concepts Worksheet

Uploaded by

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

MySQL Commands and Database Concepts Worksheet

Uploaded by

nbcffggndnxjxjd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

WORKSHEET – 9

____________________________________________________________
1. Write MySQL commands for the following:
a. To create a new database named ‘School’.
b. To open the database ‘School’
c. To list the tables in the database ‘School’
2. Give another term for (i) Attribute (ii) Tuple
3. Mention the categories of MySQL commands. Mention any two commands under each category.
4. Observe the following table carefully and write the names of the most appropriate columns, which
can be considered as (i) candidate keys and (ii) primary key (iii) Alternate keys
Code Item Qty Price TransactionDate
1001 Plastic Folder 14’’ 100 3400 2014-12-14
1004 Pen Stand Standard 200 4500 2015-01-31
1005 Stapler Mini 250 1200 2015-02-28
1009 Punching Machine Small 200 1400 2015-03-12
1003 Stapler Big 100 1500 2015-02-02

5. Consider the following DEPT and EMPLOYEE tables.


Table : DEPT
Dcode Department Location
D01 Infrastructure Delhi
D02 Marketing Delhi
D03 Media Mumbai
D05 Finance Kolkata
D04 Human Resource Mumbai
Table : EMPLOYEE
ENO NAME DOJ DOB GENDER DCODE SALARY SALGRADE
1001 George K 2013-09-02 1991-09-01 MALE D01 30000 A
1002 Ryma Sen 2012-12-11 1990-12-15 FEMALE D03 32000 A
1003 Mohitesh 2013-02-03 1987-09-04 MALE D05 30000 A
1007 Anil Jha 2014-01-17 1984-10-19 MALE D04 29000 B
1004 Manila Sahai 2012-12-09 1986-11-14 FEMALE D01 28000 B
1005 R Sahay 2013-11-18 1987-03-31 MALE D02 Null Null
1006 Jaya Priya 2014-06-09 1985-06-23 FEMALE D05 30000 A

a) Identify the primary key and foreign key (if any) in both the tables.
b) Write the degree and cardinality of the Cartesian product as well as the equi-join of the tables DEPT and
EMPLOYEE.
c) Write the degree and cardinality of natural join of the above 2 tables.
d) Write the domain of the column Gender
e) Write MySQL commands for the following:
(i) To display Eno, Name, Gender from the table Employee in ascending order of their age.
(ii) To display Name and location of all the MALE employees.
(iii) To display Name and Salary of all the employees who has the letter ‘il’ anywhere in their name.
(iv) To remove the details of all the employees with salgrade as Null.
(v) To display the Eno and Name of those employees from the table EMPLOYEE who are
born between ‘1987-01-01’ and‘1991-12-01’.
(vi) To display Dcode, name and annual salary of the employees of FINANCE department.
(The salary given in the table is monthly salary.)
(vii) To count and display FEMALE employees who have joined after ‘1986-01-01’.
(viii) To display Name and Dcode of all those employees whose salary has not been decided.
(ix) To increment the salary of all the employees with salgrade as ‘B’ by 5%.
(x) To add a new column PHNO of integer datatype in the table EMPLOYEE.
(xi) To display Employee name, their salary and their corresponding department name.
(xii) To display Employee name, dcode and their corresponding location for all the employees whose
salary is less than 30000.
(xiii) To display gender wise minimum salary.
(xiv) To display the salary of the highly paid male and female employee.
(xv) To display the average salary given under each Dcode if there are at least 2 employees
under each Dcode.

Write output for the following:


(i) Select Count(*),Dcode From Employee Group By Dcode Having Count(*)>1;
(ii) Select Distinct dcode From Employee;
(iii) Select Name,Department From Employee E,Dept D where [Link]=[Link] and Eno<1003;
(iv) Select Max(Doj), Min(Dob) From Employee;
(v) Select Gender, Avg(sal) from Employee group by Gender;
(vi) Select count(Distinct Department) from Employee;
(vii) Select Name, DOB from Employee order by DOB desc;
(viii) Select Name, Gender, Salary from Employee order by Gender, Salary desc;
(ix) Select Gender, Salgrade, min(salary) from Employee group by Gender, Salgrade;
(x) Select Gender, Min(salary) From Employee Where Salgrade=’A’ Group By Gender Having
Count(*)>1;

************************************************

You might also like