Q.Bank Solution DBMS
Q.Bank Solution DBMS
A Test -2
Lpad(String,char,number) – returns the string left padded with the character specified to a total of length
specified.
Rpad(String,char,number) – returns the string right padded with the character specified to a total of length
specified.
Ltrim(String) -removes white space or other specified characters from the left end of the string Rtrim(String)-
-removes white space or other specified characters from the right end of the string
Ans:- An aggregate function is a function where the values of multiple rows are grouped together as input
on certain criteria to form a single value of more significant meaning.
1) Count()
2) Sum()
3) Avg()
4) Min()
DBMS Question Bank Answer P.A Test -2
5) Max()
1. Count () - 1) It returns number of rows from the given table if no attribute is mentioned.
2) If some attribute is mentioned, it gives total number of not null values for that attribute.
Eg :Select count(*) from emp; Returns total number of records from emp table.
1) Select count(telephone) from emp; Returns total number of employees having telephone numbers.
2. Sum() - It give total of all values from a numeric attribute of the given table,
Eg :Select sum(salary) from emp; Returns total salary drawn of all employees from the emp table.
3. Avg () - It gives average of all the numeric values of the given attribute from the table.
Eg :Select Avg(salary) from emp; Returns average salary of employees from emp table.
4. Min () - It gives minimum of all the values of the numeric given attribute from the table.
Eg :Select Min(salary) from emp; Returns minimum salary value from emp table,
5. Max () - It gives maximum of all the values of the numeric given attribute from the table. Eg :Select
Max(salary) from emp; retunes maximum salary value from emp table,
Ans:- The GROUP BY clause is applicable when we want to use aggregate functions to more than one set of
rows. The ORDER BY clause is applicable when we want to get the data obtained by a query in the sorting
order. The HAVING clause was introduced in SQL to allow the filtering of query results based on aggregate
functions and groupings.
The following is the syntax to use GROUP BY clause in a SQL statement:
Student_Dept
Sid Sname Dept
1 Abc CS
2 Xyz EE
3 Pqr EE
4 Lmn CE
5 Uvw CE
DBMS Question Bank Answer P.A Test -2
The following is the Syntax to use the ORDER BY clause in a SQL statement:
FROM customers
GROUP BY country
HAVING clause
The HAVING clause is used to filter the results of a GROUP BY query. It allows you to specify conditions
that the groups must meet in order to be included in the results.
Example:
FROM customers
GROUP BY country
diagram.
Ans:- SQL Join statement is used to combine data or rows from two or more tables based on a common
field between them. Different types of Joins are as follows:
1) INNER JOIN or EQUI JOIN: A join which is based on equalities is called equi join. In equi join
comparison operator “=” is used to perform a Join.
2) SELF JOIN: The SQL SELF JOIN is used to join a table to itself, as if the table were two tables,
temporarily renaming at least one table in the SQL statement. Syntax: SELECT a.column_name,
b.column_name FROM table1 a, table1 b WHERE a.common_filed = b.common_field; Example: Select
x.stud_name, y.stud_name from stud_info x, stud_info y Where x.leader= y.stud_id;
DBMS Question Bank Answer P.A Test -2
3) LEFT OUTER JOIN: A left outer join retains all of the rows of the “left” table, regardless of whether
there is a row that matches on the “right” table. Syntax: Select column1name,column2name from
table1name any_alias1 ,table2name any_alias2 on any_alias1.columnname(+) = any_alias2.columnname;
OR
4) RIGHT OUTER JOIN: A right outer join retains all of the rows of the “right” table, regardless of whether
there is a row that matches on the “left” table. Syntax: Select column1name, column2name from
table1name any_alias1, table2name any_alias2 on any_alias1.columnname =any_alias2.columnname (+);
OR Select column1name, column2name from table1name any_alias1 right outer join table2 name
any_alias2 on any_alias1.columnname =any_alias2.columnname; Example: Select
last_name,department_name from employees e, departments d on e.department_id =
d.department_id(+); OR Select last_name, department_name from employees e right outer join
departments d on e.department_id = d.department_id;
5) NON EQUI JOIN: Non equi joins is used to return result from two or more tables where exact join is not
possible. Syntax: Select aliasname.column1name, aliasname.column2name from tablename alias where ;
For example: In emp table and salgrade table. The salgrade table contains grade and their low salary and
high salary. Suppose you want to find the grade of employees based on their salaries then you can use
NON EQUI join. Select e.empno, e.ename, e.sal, s.grade from emp e, salgrade s where e.sal between
s.lowsal and s.hisal;
Ans:-
START WITH 1
INCREMENT BY 1
MINVALUE 1
MAXVALUE 99999
CYCLE;
Ans:- An index in a database is a data structure that helps the database find data quickly. There are two
main types of indexes: primary and secondary. Indexes can improve query performance, but they also add
overhead.
Sparse: Only contains an entry for some of the values in the indexed column.
Ans:- A sequence in a database management system (DBMS) is a schema object that generates a series
of unique numeric values. Sequences are often used to generate primary key
values for tables, but they can also be used to generate other types of unique
values, such as order numbers, invoice numbers, and audit trail identifiers.
Uses:
Generating sequential values for columns such as order numbers and invoice numbers.
Ans:-
Advantages of views:
Disadvantages of views:
10. Explain any four date and time function with Example.
DBMS Question Bank Answer P.A Test -2
DATE_FORMAT(date_time_value, format) formats a date and time value according to a specified format.
DATE_SUB(date_time_value, interval) subtracts a specified interval from a date and time value.