0% found this document useful (0 votes)
83 views

DBMS Question Bank

The document discusses various topics related to database management systems including DBMS architecture, ER modeling, SQL queries using joins, roles of a database administrator, database concepts like entities, attributes, relationships, keys, data independence, data models, applications of DBMS and advantages and disadvantages of using a DBMS over a file system.

Uploaded by

deepak
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)
83 views

DBMS Question Bank

The document discusses various topics related to database management systems including DBMS architecture, ER modeling, SQL queries using joins, roles of a database administrator, database concepts like entities, attributes, relationships, keys, data independence, data models, applications of DBMS and advantages and disadvantages of using a DBMS over a file system.

Uploaded by

deepak
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
You are on page 1/ 33

1.Draw and explain the architecture of DBMS. Compare it with the file system.

The basic client/server architecture is used to deal with a large number of PCs, web servers,
database servers and other components that are connected with networks.

2) Explain the role of E-R model in database design.

ER Model stands for Entity Relationship Model.ER model helps to systematically analyze data
requirements to produce a well-designed database.

3) How can the two tables be joined using left outer and right outer joins?

SELECT c.customerid,
c.companyName,
orderid
FROM customers c
LEFT JOIN orders o ON o.customerid = c.customerid
ORDER BY orderid

SELECT c.customerid,
c.companyName,
orderid
FROM customers c
RIGHT JOIN orders o ON o.customerid = c.customerid
ORDER BY orderid

4) Describe any four main functions of a database administrator.


● Software installation and Maintenance.
● Data Extraction, Transformation, and Loading.
● Specialised Data Handling.
● Database Backup and Recovery.
● Security.
● Authentication.
● Capacity Planning.
● Performance Monitoring.

5) Define the following terms giving examples for each of them: Entity, Attribute, Role
and
Relationship between entities

a. Entity: Any thing in the real world with independent existence is called Entity such as an
object with physical existence (e.g., car, person, house) or conceptual existence (e.g., a
company, job, university course, account, voucher).

b. Attributes: Attributes are some properties of interest (or characteristics) that further describes
the entity such as height, weight and date of birth in case of a person and code and name in
case of accounts.

c. Relationship : It is a relational database. All entities have bonds (relations) between them.

6) Differentiate between database management system and file system.

File system Dbms

Used to manage and organise the files stored A software to store and retrieve the user’s
in the hard disk of the computer data

Redundant data is present No Redundant data is present

Less secure More secure

Query processing is not so efficient Query processing is so efficient

7) Differentiate between physical and logical data independence.

physical logical data independence.

It mainly concern about how the data is It mainly concerned about the structure or the
stored into the system. changing data definition.
It is easy to retrieve. It is difficult to retrieve because the data is
mainly dependent on the logical structure of
data.

As compared to the logical independence it is As compared to the physical independence it


easy to achieve physical data independence. is not easy to achieve logical data
independence.

Example: Change in compression Example: Add/Modify or Delete a new


techniques, Hashing algorithms and storage attribute.
devices etc.

8) Define strong and weak entity.

Strong Entity
The strong entity has a primary key. Weak entities are dependent on strong entity. Its existence
is not dependent on any other entity.

Weak Entity
The weak entity in DBMS do not have a primary key and are dependent on the parent entity. It
mainly depends on other entities.

9) Define primary key and candidate key.

Primary Key – is a column or group of columns in a table that uniquely identify every row in that
table.

Candidate Key – is a set of attributes that uniquely identify tuples in a table. Candidate Key is a
super key with no repeated attributes.This key aslo a candidate for being primary key in future

10) Define entity integrity and referential integrity constraint

Entity integrity
To ensure entity integrity, it is required that every table have a primary key. Neither the PK nor
any part of it can contain null values.

Referential integrity
Referential integrity requires that a foreign key must have a matching primary key or it must be
null. This constraint is specified between two tables (parent and child); it maintains the
correspondence between rows in these tables.

11.Define Dbms
A database management system (DBMS) is a computer program designed to manage a large
amount of structured data, and run operations on the desired data requested by the users.

12) Who is DBA? What are the responsibilities of a DBA?

A Database Administrator (DBA) is individual or person responsible for controlling,


maintenance, coordinating, and operation of database management system. Managing,
securing, and taking care of database system is prime responsibility.

13) List different types of data models.

1) Relational Data Model: This type of model designs the data in the form of rows and columns
within a table.

2) Entity-Relationship Data Model: An ER model is the logical representation of data as objects


and relationships among them

3) Object-based Data Model: An extension of the ER model with notions of functions,


encapsulation, and object identity, as well.

4)Semistructured Data Model: This type of data model is different from the other three data
models (explained above). The semistructured data model allows the data specifications at
places where the individual data items of the same type may have different attributes sets

14) List any four applications of DBMS.

Library Management System. ...


Banking. ...
Universities and colleges. ...
Credit card transactions. ...
Social Media Sites. ...
Telecommunications. ...
Finance.

15) What are the disadvantages of file system?


Disadvantages of File Processing System :
● Slow access time – ...
● Presence of redundant data – ...
● Inconsistent Data – ...
● Data Integrity Problems – ...
● Difficulty in recovery of corrupt data – ...
● Lack of Atomicity – ...
● Problem in Concurrent Access – ...
● Unauthorized Access –

16) What are the advantages of using DBMS?

1. Data Integrity
2. Data Security
3. Better data integration
4. Minimized Data Inconsistency
5. Faster Data Access

17) Define Instance and Schema?

Definition of instance: The data stored in database at a particular moment of time is called
instance of database.

Definition of schema: Design of a database is called the schema. Schema is of three types:
Physical schema, logical schema and view schema.

18) Define Physical schema.

The design of a database at physical level is called physical schema, how the data stored in
blocks of storage is described at this level.

19) Define logical schema.


Design of database at logical level is called logical schema, programmers and database
administrators work at this level, at this level data can be described as certain types of data
records gets stored in data structures, however the internal details such as implementation of
data structure is hidden at this level (available at physical level).

22) What are the various kinds of interactions catered by DBMS?

The various kind of interactions catered by DBMS are:

Data definition
Update
Retrieval
Administration

23) Who proposed the relational model?


E.F . CODD

Long wale

Q2. Construct an E-R diagram for a hospital management system with a set of doctors
and a set of
patients. With each patient, a series of various tests and examinations are conducted. On
the- basis
of preliminary report.
Q3. a) Discuss the advantages and disadvantages of DBMS.

Advantages of DBMS

● Controls database redundancy: All the data is stored in one place, and that recorded in the
database and hence controls the redundancy in the database.
● Data sharing: DBMS allows users with authority to share the data in the database with
multiple users.
● Easy Maintenance: The centralized nature of the database helps in the easy maintenance
of the data.
● Reduce time: It reduces the maintenance need and development time.
● Backup: It automatically backs up data to maintain its integrity in case of failure.
● Multiple user interfaces: It offers a number of user interface to multiple users.

Disadvantages of DBMS

● Cost of software and hardware: It requires a number of high powered processors and
large size memory to run DBMS.
● Size: a Large amount of storage size is required to run DBMS efficiently.
● Complexity: DBMS adds an additional layer of complexity to the data.
● Higher impact of failure: DBMS faces a higher risk of losing the data since all the data is
stored at a single location and a catastrophic failure can wipe it all.

b) Why is relation database approach better than earlier methods?

1. Data redundancy

2. Access control

3. Authorization, authentication

4. Recovery and backup

5. Constraints and complex relationships

6. Faster access manipulation


Q4. Consider the following relational schema:

Emp (empno, enarne, job, sai, comm., hir-edate, deptno)

Dept (deptno, dname, iocation )

Give an expression in SQL for the following Queries:

a) Find the narnes of employees who work in deptno 10 and 20'

select ename from emp where deptno = 10 or deptno = 20 ;

B) Increase the salary by Rs 15OO for the employees who are 'CLERK'.

Alter table emp set sal=sal+1500 where job=’CLERK’;

c) Display the detaiis of employees who work in same deptno as of the empioyee 'SMITH'.

C) Select * from emp where depno = (select depno from emp where ename = "Smith")

d) Create the table Dept.

D) create table deptno ( deptno int primary key, dname varchar(20), location varchar(50));

e) Display total salary of employees of each deptno and display those deptno whose total
salary is more than Rs. 30000.

E) select max(sal) from emp group by deptno having max(sal) > 30000
Q5.a) Write a short note on three scheme architecture.

Three-tier architecture is a well-established software application architecture that organizes


applications into three logical and physical computing tiers: the presentation tier, or user
interface; the application tier, where data is processed; and the data tier, where the data
associated with the application is stored and managed.

b) Explain different types of Data Independence.

Data Independence

Data independence can be explained using the three-schema architecture.

1. Logical Data Independence

Logical data independence refers characteristic of being able to change the conceptual schema
without having to change the external schema.

2. Physical Data Independence

Physical data independence can be defined as the capacity to change the internal schema without
having to change the conceptual schema.

c) Write a short note on the following

1. Primary Key

2. Candidate Key

3. Super Key

4. Derived attribute

5. Multivalued attribute

1.In the relational model of databases, a primary key is a specific choice of a minimal set of
attributes that uniquely specify a tuple in a relation. Informally, a primary key is "which
attributes identify a record," and in simple cases constitute a single attribute: a unique ID.

2.The minimal set of attributes that can uniquely identify a tuple is known as a candidate key.

3.The set of attributes that can uniquely identify a tuple is known as Super Key. A super key is a
group of single or multiple keys which identifies rows in a table.

* It supports NULL values.


4.A derived attribute as the name suggests is the one that can be. derived or calculated with the
help of other attributes present themselves

5.A multivalued attribute of an entity is an attribute that can have more than one value associated
with the key of the entity

Q6. (a) Explain the term Generalization and Specialization with suitable example.

1. Generalization :

It works on the principle of bottom up approach. In Generalization lower level functions are
combined to form higher level function which is called as entities. This process is repeated
further to make advanced level entities.

In the Generalization process properties are drawn from particular entities and thus we can create
generalized entity. We can summarize Generalization process as it combines subclasses to form
superclass.

Example of Generalization –
Consider two entities Student and Patient. These two entities will have some characteristics of
their own. For example Student entity will have Roll_No, Name and Mob_No while patient will
have PId, Name and Mob_No characteristics. Now in this example Name and Mob_No of both
Student and Patient can be combined as a Person to form one higher level entity and this process
is called as Generalization Process.

2. Specialization :

We can say that Specialization is opposite of Generalization. In Specialization things are broken
down into smaller things to simplify it further. We can also say that in Specialization a particular
entity gets divided into sub entities and it’s done on the basis of it’s characteristics. Also in
Specialization Inheritance takes place.

Example of Specialization –

Consider an entity Account. This will have some attributes consider them Acc_No and Balance.
Account entity may have some other attributes like Current_Acc and Savings_Acc. Now
Current_Acc may have Acc_No, Balance and Transactions while Savings_Acc may have
Acc_No, Balance and Interest_Rate henceforth we can say that specialized entities inherits
characteristics of higher level entity.
After applying generalization and specialization, the structure of resultant figures are same.

7 (a)Explain the SQL operators BETWEEN, AND, IN, LIKE and IS_NULL by taking
suitable examples.

BETWEEN

The BETWEEN operator selects values within a given range. The values can be numbers, text,
or dates.

The BETWEEN operator is inclusive: begin and end values are included.

Example
SELECT * FROM Products

WHERE Price BETWEEN 10 AND 20;

AND

The WHERE clause can be combined with AND operator.


The AND operator is used to filter records based on more than one condition:
The AND operator displays a record if all the conditions separated by AND are TRUE.
Example
SELECT * FROM Customers

WHERE Country='Germany' AND City='Berlin';

IN

The IN operator allows you to specify multiple values in a WHERE clause.

The IN operator is a shorthand for multiple OR conditions.

Example
SELECT * FROM Customers

WHERE Country IN ('Germany', 'France', 'UK');

LIKE

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

There are two wildcards often used in conjunction with the LIKE operator:

● The percent sign (%) represents zero, one, or multiple characters


● The underscore sign (_) represents one, single character

Example
The following SQL statement selects all customers with a CustomerName
starting with "a":
SELECT * FROM Customers
WHERE CustomerName LIKE 'a%';

The following SQL statement selects all customers with a CustomerName ending
with "a":

SELECT * FROM Customers

WHERE CustomerName LIKE '%a';


The following SQL statement selects all customers with a CustomerName that
have "or" in any position

SELECT * FROM Customers

WHERE CustomerName LIKE '%or%';

The following SQL statement selects all customers with a CustomerName that
have "r" in the second position:

SELECT * FROM Customers

WHERE CustomerName LIKE '_r%';

The following SQL statement selects all customers with a CustomerName that
starts with "a" and are at least 3 characters in length:

SELECT * FROM Customers

WHERE CustomerName LIKE 'a___’;

The following SQL statement selects all customers with a ContactName that
starts with "a" and ends with "o":

SELECT * FROM Customers

WHERE ContactName LIKE 'a%o';

The following SQL statement selects all customers with a CustomerName that
does NOT start with "a":

SELECT * FROM Customers

WHERE CustomerName NOT LIKE 'a%';


IS NULL

The IS NULL operator is used to test for empty values (NULL values).

The following SQL lists all customers with a NULL value in the "Address" field:

example:

SELECT CustomerName, ContactName, Address

FROM Customers

WHERE Address IS NULL;

(b) Discus various data types available in SQL.

SQL Data Types

SQL data types can be broadly divided into following categories.

1. Numeric data types such as int, tinyint, bigint, float, real, etc.
2. Date and Time data types such as Date, Time, Datetime, etc.
3. Character and String data types such as char, varchar, text, etc.
4. Unicode character string data types, for example nchar, nvarchar, ntext, etc.
5. Binary data types such as binary, varbinary, etc.
6. Miscellaneous data types – clob, blob, xml, cursor, table, etc

(c)SQL allows attributes to have a special value NULL, which is called the null value. What
are three common interpretations that can be put on null values?

A NULL value is used to represent a missing value, but that it usually has one of three different
interpretations:
The value unknown (value exists but is not known)
Value not available (exists but is purposely withheld)

Attribute not applicable (undefined for this tuple)


Q9. Differentiate between:

a) Primary Key and Foreign Key

b) View and Indexes

Primary Key Foreign Key

The primary key uniquely identifies a record in the table.

A foreign key is a field in the table that is the primary key in another table.

Primary Key can't accept null values.

A foreign key can accept multiple null values.

By default, the Primary key is clustered index, and data in the database table is physically
organized in the sequence of the clustered index.

Foreign keys do not automatically create an index, clustered or non-clustered. You can manually
create an index on a foreign key.

We can have only one Primary key in a table.

We can have more than one foreign key on a table.

B)VIEW
View is a logical table. It is a physical object which stores data logically. View just refers to data
that is tored in base tables.

A view is a logical entity. It is a SQL statement stored in the database in the system tablespace.
Data for a view is built in a table created by the database engine in the TEMP tablespace.

INDEX

Indexes are pointres that maps to the physical address of data. So by using indexes data
manipulation becomes faster.

An index is a performance-tuning method of allowing faster retrieval of records. An index


creates an entry for each value that appears in the indexed columns.

Q12 (a) List the difference between Equijoin and Natural join. Give example of each join
operation.

Equi Join
Equi join is a special type of join in which we use only an equality operator.
Hence, when you make a query for join using equality operator then that join
query comes under Equi join.

The equi join creates a JOIN for equality or matching of the single or multiple
column values of the relative tables. Apart from that, the equi join also create the
JOIN by using JOIN along with the ON clause and then providing the names of
the columns with their relative tables to check equality using the equal operator.

Below is a simple example of equi having the use of ON condition.

Equi Join Example


SELECT * FROM tblEmp JOIN tblDept

ON tblEmp.DeptID = tblDept.DeptID;
--Using Clause is not supported by SQL Server

--Oracle and MySQL Query

SELECT * FROM tblEmp INNER JOIN tblDept USING(DeptID)

Natural Join
A natural join is a type of equi join which occurs implicitly by comparing all the
same names columns in both tables. The join result has only one column for
each pair of equally named columns.

In other words, the Natural Join helps to join the two tables based on the same
attribute name and the datatypes. The result of the JOIN table will contain all the
attributes of both tables but keep only one copy of each common column
accordingly.

Below is an example of a natural join. After using the Natual join, the result set
will contain only one column for each pair of equally named columns. If there are
no columns with the same names are found, then the result will be a "cross join".

Natural Join Example


--Run in Oracle and MySQL

SELECT * FROM tblEmp NATURAL JOIN tblDept

What are the problems caused by data redundancies? Can data redundancies be
completely eliminated when a database approach is used? Explain this with the help of an
example

No, data redundancies cannot be completely eliminated


when the database approach is used
Explanation:

● Data redundancy is the duplication of data. It his creates duplicated data at various locations
and storage space wastage
● Data redundancy cannot be totally removed from the database, though there needs to be
controlled redundancy.
● Database normalisation prevents replication and allows the best possible storage usage

Q14 (a) Explain the three schema architecture with diagram. Compare traditional
approach and DBMS Approach.

The three-schema architecture divides the database into three-level used to create a separation
between the physical database and the user application. In simple terms, this architecture hides
the details of physical storage from the user.

The database administrator (DBA) responsible is to change the structure of database storage
without affecting the user’s view. It deals with the data, the relationship between them and the
different access methods implemented on the database. The logical design of database is called a
schema

This architecture contains three layers of database management system, which are as follows −

● External level
● Conceptual level
● Internal level

External/ View level

This is the highest level of database abstraction. It includes a number of external schemas or user
views. This level provides different views of the same database for a specific user or a group of
users. An external view provides a powerful and flexible security mechanism by hiding the parts
of the database from a particular user.

Conceptual or Logical level

This level describes the structure of the whole database. It acts as a middle layer between the
physical storage and user view. It explains what data to be stored in the database, what the data
types are, and what relationship exists among those data. There is only one conceptual schema
per database.

This level describes the structure of the whole database. It acts as a middle layer between the
physical storage and user view. It explains what data to be stored in the database, what the data
types are, and what relationship exists among those data. There is only one conceptual schema
per database.

Internal or Physical level

This is the lowest level of database abstraction. It describes how the data is stored in the database
and provides the methods to access data from the database. It allows viewing the physical
representation of the database on the computer system.

The interface between the conceptual and internal schema identifies how an element in the
conceptual schema is stored and how it may be accessed. It is one which is closest to physical
storage. The internal schema not only defines different stored record types, but also specifies
what indices exist, how stored fields are represented.

The three level schema architecture in DBMS is given below −


(b) Explain Domain, Entity Integrity and referential integrity constraints.

Integrity Constraints

● Integrity constraints are a set of rules. It is used to maintain the quality of information.
● Integrity constraints ensure that the data insertion, updating, and other processes have to
be performed in such a way that data integrity is not affected.
● Thus, integrity constraint is used to guard against accidental damage to the database.

Types of Integrity Constraint

1. Domain constraints

● Domain constraints can be defined as the definition of a valid set of values for an
attribute.
● The data type of domain includes string, character, integer, time, date, currency, etc. The
value of the attribute must be available in the corresponding domain.

Example:
2. Entity integrity constraints

● The entity integrity constraint states that primary key value can't be null.
● This is because the primary key value is used to identify individual rows in relation and if
the primary key has a null value, then we can't identify those rows.
● A table can contain a null value other than the primary key field.

Example:

3. Referential Integrity Constraints

● A referential integrity constraint is specified between two tables.


● In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary
Key of Table 2, then every value of the Foreign Key in Table 1 must be null or be
available in Table 2.
Example:

15 (b) What do you mean by Data independence. Differentiate between physical and
Logical Data independence.

Data independence.

• Data independence can be explained using the three-schema architecture.


• Data independence refers characteristic of being able to modify the schema at one level of
the database system without altering the schema at the next higher level.
• There are two types of data independence:
o Logical Data Independence
o Physical Data Independence
physical Data independence.

• Physical data independence can be defined as the capacity to change the internal schema
without having to change the conceptual schema.
• If we do any changes in the storage size of the database system server, then the Conceptual
structure of the database will not be affected.
• Physical data independence is used to separate conceptual levels from the internal levels.
• Physical data independence occurs at the logical interface level.

Logical Data independence

o Logical data independence refers characteristic of being able to change the conceptual
schema without having to change the external schema.
o Logical data independence is used to separate the external level from the conceptual view.
o If we do any changes in the conceptual view of the data, then the user view of the data would
not be affected.
o Logical data independence occurs at the user interface level.

Q16

(a) What is a join, why is it required? What are the categories of join. Explain self join,
outer join, natural join etc.

Join statement is used to join two tables based on their common column.

it is used for various purposes like:


1) combining two tables

2) using data of one table which is used to obtain the final output from other table.

3) combining the data enable a single user view

Here are the different types of the JOINs in SQL:

● (INNER) JOIN: Returns records that have matching values in both tables
● LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from
the right table
● RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records
from the left table
● FULL (OUTER) JOIN : Returns all records when there is a match in either left or right table

Natural join
Natural join is an SQL join operation that creates join on the base of the common
columns in the tables. To perform natural join there must be one common
attribute(Column) between two tables. Natural join will retrieve from multiple relations.
It works in three steps.
Syntax :
We will perform the natural join query by using the following syntax.

SELECT *

FROM TABLE1

NATURAL JOIN TABLE2;

1. SELF JOIN: As the name signifies, in SELF JOIN a table is joined to itself. That is, each row of the
table is joined with itself and all other rows depending on some conditions. In other words we
can say that it is a join between two copies of the same table.Syntax:

SELECT a.coulmn1 , b.column2

FROM table_name a, table_name b

WHERE some_condition;

Example Queries(SELF JOIN):

SELECT a.ROLL_NO , b.NAME

FROM Student a, Student b

WHERE a.ROLL_NO < b.ROLL_NO;

A. INNER JOIN

The INNER JOIN keyword selects all rows from both the tables as long as the condition is satisfied. This
keyword will create the result-set by combining all rows from both the tables where the condition
satisfies i.e value of the common field will be the same. 

Syntax: 

SELECT table1.column1,table1.column2,table2.column1,....

FROM table1

INNER JOIN table2

ON table1.matching_column = table2.matching_column;

B. LEFT JOIN
This join returns all the rows of the table on the left side of the join and matches rows for the table on
the right side of the join. For the rows for which there is no matching row on the right side, the result-set
will contain null. LEFT JOIN is also known as LEFT OUTER JOIN.

Syntax: 

SELECT table1.column1,table1.column2,table2.column1,....

FROM table1

LEFT JOIN table2

ON table1.matching_column = table2.matching_column;

RIGHT JOIN

RIGHT JOIN is similar to LEFT JOIN. This join returns all the rows of the table on the right side of the join
and matching rows for the table on the left side of the join. For the rows for which there is no matching
row on the left side, the result-set will contain null. RIGHT JOIN is also known as RIGHT OUTER JOIN. 

Syntax: 

SELECT table1.column1,table1.column2,table2.column1,....

FROM table1

RIGHT JOIN table2

ON table1.matching_column = table2.matching_column;

D. FULL JOIN

FULL JOIN creates the result-set by combining results of both LEFT JOIN and RIGHT JOIN. The result-set
will contain all the rows from both tables. For the rows for which there is no matching, the result-set will
contain NULL values.

Syntax:  

SELECT table1.column1,table1.column2,table2.column1,....

FROM table1

FULL JOIN table2

ON table1.matching_column = table2.matching_column;

table1: First table.

table2: Second table

matching_column: Column common to both the tables.


(b) Explain group by clause and having with an example.

1. Having Clause: 
Having Clause is basically like the aggregate function with the GROUP BY clause. The HAVING clause is
used instead of WHERE with aggregate functions. While the GROUP BY Clause groups rows that have the
same values into summary rows. The having clause is used with the where clause in order to find rows
with certain conditions. The having clause is always used after the group By clause.  

ex:

SELECT COUNT (SALARIES) AS COUNT_SALARIES, EMPLOYEES

FROM EMPLOYEES

GROUP BY SALARIES

HAVING COUNT(SALARIES) > 1;

2. Group By Clause: 
The GROUP BY clause is often used with aggregate functions (MAX, SUM, AVG) to group the results by
one or more columns or In simple words we can say that The GROUP BY clause is used in collaboration
with the SELECT statement to arrange required data into groups. 
The GROUP BY statement groups rows that have the same values. This Statement is used after the where
clause. This statement is often used with some aggregate function like SUM, AVG, COUNT atc. to group
the results by one or more columns.  

ex:

SELECT COUNT (SALARIES) AS COUNT_SALARIES, EMPLOYEES

FROM EMPLOYEES

GROUP BY SALARIES;

Q17

(a) Write Sql queries for the following tables.

Employee

Empno Ename Job MGR Hiredate Sal Comm. Deptno.

Department Dname Dnumber Dloc

· List all the employee their salary.

Select ename,sal from employee;

· List the Different jobs.


Select distinct (job) from employee;

· List the employee names having l' as the second character.

Select ename from employee where ename like '_I%';

· List the employees who are from department 30 and their salary is more than 40,000.

Select ename from employee where deptno = 30 and salary > 40000

(b) What is view. Explain with the help of an example.

Views in SQL are kind of virtual tables. A view also has rows and columns as they are in a real
table in the database. We can create a view by selecting fields from one or more tables present in
the database. A View can either have all the rows of a table or specific rows based on certain
condition.

Syntax:

CREATE VIEW view_name AS

SELECT column1, column2.....

FROM table_name

WHERE condition;

Example

CREATE VIEW DetailsView AS

SELECT NAME, ADDRESS

FROM StudentDetails

WHERE S_ID < 5;


Ache se padho bhaiyo 🙂

You might also like