Important Questions
Important Questions
Answer: Database is an organized collection of related data where the data is stored and organized to
serve some specific purpose.
For Example, A librarian maintain a database of all the information related to the books that are
available in the library.
Q #2) Define DBMS.
Answer: DBMS stands for Database Management System. It is a collection of application programs
which allow the user to organize, restore and retrieve information about data efficiently and as
effectively as possible.
Some of the popular DBMS’s are MySql, Oracle, Sybase, etc.
Q #19) What are the advantages and disadvantages of views in the database?
Answer: Advantages of Views:
As there is no physical location where the data in the view is stored, it generates output
without wasting resources.
Data access is restricted as it does not allow commands like insertion, updation, and deletion.
Disadvantages of Views:
The view becomes irrelevant if we drop a table related to that view.
Much memory space is occupied when the view is created for large tables.
Q #20) What do you understand by Functional dependency?
Answer: A relation is said to be in functional dependency when one attribute uniquely defines
another attribute.
For Example, R is a Relation, X and Y are two attributes. T1 and T2 are two tuples. Then,
T1[X]=T2[X] and T1[Y]=T2[Y]
employee_info table:
a) Inner JOIN: Inner JOIN is also known as a simple JOIN. This SQL query returns results from
both the tables having a common value in rows.
SQL Query:
SELECT * from employee, employee_info WHERE employee.EmpID = employee_info.EmpID ;
Result:
b) Natural JOIN: This is a type of Inner JOIN that returns results from both the tables having the
same data values in the columns of both the tables to be joined.
SQL Query:
SELECT * from employee NATURAL JOIN employee_info;
Result:
c) Cross JOIN: Cross JOIN returns the result as all the records where each row from the first table is
combined with each row of the second table.
SQL Query:
SELECT * from employee CROSS JOIN employee_info;
Result:
Let us do some modification in the above tables to understand Right JOIN, Left JOIN, and Full
JOIN.
employee table:
employee_info table:
a) Right JOIN: Right JOIN is also known as Right Outer JOIN. This returns all the rows as a result
from the right table even if the JOIN condition does not match any records in the left table.
SQL Query:
SELECT * from employee RIGHT OUTER JOIN employee_info on (employee.EmpID = employee_info.EmpID);
Result:
b) Left JOIN: Left JOIN is also known as Left Outer JOIN. This returns all the rows as a result of
the left table even if the JOIN condition does not match any records in the right table. This is exactly
the opposite of Right JOIN.
SQL Query:
SELECT * from employee LEFT OUTER JOIN employee_info on (employee.EmpID = employee_info.EmpID);
Result:
c) Outer/Full JOIN: Full JOIN return results in combining the result of both the Left JOIN and
Right JOIN.
SQL Query:
SELECT * from employee FULL OUTER JOIN employee_info on (employee.EmpID = employee_info.EmpID);
Result:
a) Write the SELECT command to display the details of the employee with empid as 1004.
SQL Query:
SELECT empId, empName, Age, Address from Employee WHERE empId = 1004;
Result:
b) Write the SELECT command to display all the records of table Employees.
SQL Query:
SELECT * from Employee;
Result:
c) Write the SELECT command to display all the records of the employee whose name starts with
the character ‘R’.
SQL Query:
SELECT * from Employee WHERE empName LIKE ‘R%’;
Result:
d) Write a SELECT command to display id, age and name of the employees with their age in both
ascending and descending order.
SQL Query:
SELECT empId, empName, Age from Employee ORDER BY Age;
Result:
e) Write the SELECT command to calculate the total amount of salary on each employee from the
below Emp table.
Emp table:
SQL Query:
SELECT empName, SUM(Salary) from Emp GROUP BY empName;
Result: