2 marks question answers
2 marks question answers
Applications of DBMS 2m
•Banking
•Telecom
•Universities
•Airways
Followingarethedatabaseusers: 2m
1.NaiveUsers:Unsophisticated users
•Instance:
The data stored in database at a particular moment of time is called instance of database.
Data Independence 2m
•Definition:Data independence is ability to modify a schema definition in one level with out affecting aschema definition In the next higher level.
1.Data Redundancy :
•Redundancy is the concept of repetition of data i.e. each data may have more than a single copy.
•The file system cannot control the redundancy of data as each user defines and maintains the needed files for a specific application to run.
2. Data Sharing:
•The file system does not allow sharing of data or sharing is too complex.
3. Data integrity:
•There may be cases when some constraints need to be applied to the data before inserting it into the database.
•The file system does not provide any procedure to check these constraints automatically.
•Lowest Level
•It tells actual location of data that is being stored by the user
•Defines what data is stored in database and what relationship exist among those data
•It decides structure of entire database
•Different views of same database can be created for user to interact with database for user friendly approch
• The data stored in a database, may it be user data or metadata, must be a value of some table cell.
• Everything in a database must be stored in a table format.
• One well Structured language must be there to provide all manners of access to the data stored in the database. Ex. : SQL etc. If the database access to the data without the use of this
language, then that is a violation
• All the views of a database, which can theoretically be updated, must also be updatable by the system.
Draw and explain overall structure of DBMS
• Overall structure of DBMS
• •Database Management system (DBMS) is a software that allows
access to data stored in a database and provides an easy and
effective method of
• 1.Definingthe information
• 2.Storingthe information.
• 3.Manipulationthe information.
• •Components of DBMS
• 1.Query processor
• 2.Storage manager
• 3.Disk storage
Q12. Enlist any four aggregate functions.
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. Aggregate functions are :
Count()
Sum()
Avg()
Min()
Max()
1. Count () : It returns number of rows from the given table if no attribute is mentioned. If some attribute is
mentioned, it gives total number of not null values for that attribute.
Returns total number of employees having telephone numbers. 2. 2. Sum() : It give total of all values from a
numeric attribute of the given table.
Avg () : It gives average of all the numeric values of the given attribute from the table.
Min () : It gives minimum of all the values of the numeric given attribute from the table.
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:
A cursor is a temporary work area created in system memory when a SQL statement is executed. A cursor is
a set of rows together with a pointer that identifies a current row. It is a database object to retrieve data
from a result set one row at a time. It is useful when we want to manipulate the record of a table in a
singleton method, in other words one row at a time. In other words, a cursor can hold more than one row,
but can process only one row at a time. The set of rows the cursor holds is called the active set.
Implicit cursor: these types of cursors are generated and used by the system during the manipulation of a
DML query. An implicit cursor is also generated by the system when a single row is selected by a SELECT
command. Programmers cannot control the implicit cursors.
Explicit cursor: this type of cursor is created by the user when the select command returns more than one
row, and only one row is to be processed at a time. An explicit cursor can move from one row to another in a
result set. An explicit cursor uses a pointer that holds the record of a row.
Open: this step is done before the cursor is used to fetch the records.
Close: once the processing of the data is done, the cursor can be closed.
Example:
declare
name emp_details.ename%type;
begin
loop
dbms_output.put_line('record updated');
end loop;
end;
Q14. Enlist arithmetic and logical SQL operators.
ANS:
AND operator
1. External level
2. Conceptual level
3. Internal level
• External level
It is also called view level because several users can view their desired data from this level which is internally
fetched from database with the help of conceptual and internal level mapping. The user doesn’t need to know
the database schema details such as data structure; table definition etc. user is only concerned about data
which is what returned back to the view level after it has been fetched from database which is present at the
internal level. External level is the top level of the three level DBMS architecture.
• Conceptual level
It is also called logical level. The whole design of the database such as relationship among data, schema of data
etc. are described in this level. Database constraints and security are also implemented in this level of
architecture.
• Internal level
This level is also known as physical level. This level describes how the data is stored in the storage devices. This
level is also responsible for allocating space to the data. This is the lowest level of the architecture.
Q16. Write SQL queries for following: i) Create table student with following attributes using suitable data types.
Roll no., as primary key, name, marks as not null and city. ii) Add column Date of Birth in above student table.
iii) Increase the size of attribute name by 10 in above student table. iv) Change name of Student table to stud.
ANS: i) CREATE TABLE Student
city varchar(20)
);
Q17.Write and Explain the syntax for creating and dropping indexes with an example.
ANS:
CREATE INDEX
The CREATE INDEX command is used to create indexes in tables. It allows duplicate values. Indexes are used to
retrieve data from the database very fast. The users cannot see the indexes; they are just used to speed up
searches/queries.
Syntax:
Example:
The following SQL creates an index named id_firstname on the FirstName column in the Student table:
DROP INDEX
Syntax:
Example:
ANS:
n number; r:=mod(n,10);
i number; rev:=(rev*10)+r;
n:=&n; end;
Q19. Distinguish between network model and hierarchical model.
ANS :
ANS:
Exception Handling: Exception is nothing but an error. Exception can be raise when DBMS encounters errors or
it can be raised explicitly.
When the system throws a warning or has an error it can lead to an exception. Such exception needs to be
handled and can be defined internally or user defined.
Exception handling is nothing but a code block in memory that will attempt to resolve current error condition.
Syntax:
DECLARE ;
Declaration section
…executable statement;
EXCEPTION
END;
Types of Exception:
Are always automatically raised whenever related error occurs. The most common errors that can occur during
the execution of PL/SQL. Not declared explicitly i.e. cursor already open, invalid cursor, no data found, zero
divide and too many rows etc. Programs are handled by system defined Exceptions.
It must be declare by the user in the declaration part of the block where the exception is used. It is raised
explicitly in sequence of statements using: Raise_application_error(Exception_Number, Error_Message);
Q21. Explain joins in SQL with examples. ANS:
JOIN:
A SQL join is an instruction to combine data from two sets of data (i.e. two tables).A JOIN clause is used to
combine rows from two or more tables, based on a related column between them. SQL Join types are as
follows:
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.
Syntax:
Example:
2. 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:
Example:
3) 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 right outer join table2 name any_alias2 on
any_alias1.columnname =any_alias2.columnname;
Example:
Select last_name, department_name from employees e right outer join departments d on e.department_id =
d.department_id;
ANS:
Function: Function is a logically grouped set of SQL and Pl/SQL statements that perform a specific task.
A function is same as a procedure except that it returns a value. A function is created using the CREATE
FUNCTION statement.
1. Atomicity: When one transaction takes place, many operations occur under one transaction. Atomicity
means either all operations will take place property and reflect in the database or none of them will be
reflected.
2. Consistency: Consistency keeps the database consistent. Execution of a transaction needs to take place in
isolation. It helps in reducing complications of executing multiple transactions at a time and preserves the
consistency of the database.
3. Isolation: It is necessary to maintain isolation for the transactions. This means one transaction should not be
aware of another transaction getting executed. Also their intermediate result should be kept hidden.
4. Durability: When a transaction gets completed successfully, it is important that the changes made by the
transaction should be preserved in database in spite of system failures.
2. Creating storage structure: DBA allocate or decide the space to store the database.
3. Create grant access methods: Different access methods to access the database can be granted by DBA to
the users.
4. Schema modification: The database or schema which is already defined can be modified by DBA as per the
requirements.
5. Granting authorization: To access the different databases, DBA can grant the authorization to authorized
users only.
6. Performance tuning: The problems/errors arise in database accessing; can be resolved by DBA to increase
the performance.
7. Regular maintenance: DBA can monitor the transactions in database and maintain the database error free
by doing the regular maintenance.
Q25. Write and Explain the syntax for creating database trigger.
ANS:
Database trigger:
Triggers can be referred as stored procedures that are fired or executed when an INSERT, UPDATE or DELETE
statement is given against the associated table.
ANS:
Database recovery techniques are used to restore the original data in system from backup. Backward and
forward recovery is two types of database recovery.
Recovery Techniques:
3. Checkpoints
1. Log based recovery: It records sequence of log records, which includes all activities done by database users.
In case of database failure, by referring the log records users can easily recover the data.
ANS:
Database recovery techniques are used to restore the original data in system from backup. Backward and
forward recovery is two types of database recovery.
Recovery Techniques:
3. Checkpoints
1. Log based recovery: It records sequence of log records, which includes all activities done by database users.
In case of database failure, by referring the log records users can easily recover the data.
ANS:
Database recovery techniques are used to restore the original data in system from backup. Backward and
forward recovery is two types of database recovery.
Recovery Techniques:
3. Checkpoints
1. Log based recovery: It records sequence of log records, which includes all activities done by database users.
It records the activities when user changes the database.
In case of database failure, by referring the log records users can easily recover the data.
Alter sequence:
Syntax:
Dropping sequence:
Syntax:
ANS:
A view is like a window into the data stored in a database. It doesn’t actually store any data on its own.
Instead, it shows data from one or more tables based on a query (a question or request for information). You
can think of it like a saved search or a shortcut that you can use over and over again to get certain information.
When you use a view, it looks like you’re working with a regular table, but in reality, the database just runs the
query behind the scenes and gives you the result.
· Virtual Table: A view is not a real table; it only represents data from existing tables.
· Read-Only or Updatable: Depending on the complexity of the view, it can be read-only (if it involves complex
joins or aggregations) or updatable (if it's a simple query on a single table).
· Simplifies Queries: Views can encapsulate complex queries, making them easier to reuse.
· Security: Views can be used to restrict access to specific columns or rows of data.
Example :
FROM Employees e
ANS:
An index in a database is like a bookmark or table of contents that helps the database find and access data
faster. Instead of searching through all the rows in a table, the database can use the index to quickly locate the
data you need.
Types of Indexes:
Syntax :
2. Multi-column Index (Composite Index): An index created on multiple columns. It helps when you often
query based on more than one column.