0% found this document useful (0 votes)
30 views7 pages

Untitled Document-3

Uploaded by

pruthvi07u
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)
30 views7 pages

Untitled Document-3

Uploaded by

pruthvi07u
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/ 7

Dbms

Q1. list date and time functions in sql

->
Sql date and time functions are used to perform various operations on date
and time provided by the user following are sql date and time function

1) CURDATE();
Provides current date
Syntax: SELECT CURDATE();

2) CURTIME();
a) Provides current time
b) Syntax: SELECT CURTIME();

3) CURRENT_TIMESTAMP();
a) Provides current time as a timestamp.
b) Syntax: SELECT CURRENT_TIMESTAMP();

4) NOW();
a) Retrieves current date and time as timestamp
b) Syntax: NOW();

5) SYSDATE();
a) Provides current date and time used in sql or oracle
b) Syntax: SELECT SYSDATE();

Q.2 list advantages of PL/SQL

->
1) performance : PL/SQL reduces network traffic by combining multiple sql
queries in one unit
2) Modularity : Using PL/SQL code can be combined into different
procedures & functions which increase modularity
3) Exception handling/error handling : PL/SQL enables you to handle
exceptions more effectively thus reducing over all errors.
4) Security : PL/SQL provides strong security measures by granting
specific privileges to stored procedures and functions helping to
restrict data.

Q.3 Explain database trigger.

->
1) Database triggers are a stored PL/SQL program unit ie. procedures which
are associated with a specific database table.
2) Database triggers automatically executes when a given SQL operation
like (insert, delete, update, delete) executes.
3) A database trigger has 3 parts
a) Triggering event
b) A optional trigger
c) Trigger action
4) Syntax:
CREATE TRIGGER (trigger name)
(BEFORE/AFTER)
{INSERT/UPDATE/DELETE}
ON (table name)
[FOR EACH ROW]
[TRIGGER]
5) Example:
CREATE TRIGGER meter_reading_insert
AFTER
INSERT ON meter_readings
FOR EACH ROW
BEGIN
CALL generate_invoice();
END;

Q.4 List type of database users


1) Database administrator (DBA): Database Administrator defines the
schema.
2) Database designer: the developer who designs the database.
3) Application developer: Develops applications that interact with the
database.
4) End User: Regular users who access data for specific needs, often
through an application.
5) Sophisticated Users
6) Power User: The user who needs more access to data than an end user

Q.5 Explain state of transaction with diagram


1) Active : a transaction goes into an active state when the code/query
starts execution.
2) Partially committed: a transaction is said to be partially committed
when it executes but the changes are yet to be saved in this states few
changes can be rolled back
3) Committed: a transaction is said to be committed when the transaction
executes completely and the changes are stored permanently.
4) Failed: a transaction is said to be failed when some error has occurred
or the transaction is stopped halfway through.

Q.6 Write a PL/SQL program to print the sum of odd numbers using a for loop.
DECLARE
sum_of_odd:= 0;
n NUMBER := 10;
FOR i IN 1..20 LOOP
IF MOD(i*2)=0 THEN
sum_of_odd := sum_of_odd + i;
END IF:
END LOOP

Q.7 Difference between Procedure and function


PROCEDURE FUNCTION

Procedure can return a value using A function always returns a value


the “IN OUT” & “OUT” argument

A procedure allows a transaction A function does not allows


management transaction management

A procedure cannot be operated in the A function can be executed in the


‘SELECT’ query. ‘SELECT’ query.

Syntax: CREATE OR REPLACE Syntax: CREATE FUNCTION function_name


procedure_name[parameter] return_datatype;
IS (IS/AS)
Variable declaration; BEGIN
BEGIN //statements
//Statements EXCEPTIONS
END; //statements
END;

Q.8 write PL/SQL program to print larger of 3 numbers imputed by the user
DECLARE
a NUMBER:= &NUM1;
b NUMBER:= &NUM2;
C NUMBER:= &NUM3;
largest NUMBER;
BEGIN
IF (a<b) AND (a>c) THEN
Largest := a;
ELSEIF (b>c) THEN
Largest :=b;
ELSE
Largest :=c;
END IF;
DBMS_OUTPUT.PUT_LINE(‘Largest number is: ‘|| largest);
END;

Q.9) Create, update and delete a view.


1) CREATE:
Syntax: CREATE VIEW view_name
AS
SELECT column1..column2..columnN
FROM (table_name)
WHERE condition;
Example: CREATE VIEW emp
AS
SELECT name, salary, FROM employees
WHERE department = ‘sales’;
2) DELETE:
Syntax: DELETE FROM view_name
WHERE condition;
Example: DELETE FROM emp
WHERE name = ‘john’;
3) UPDATE:
Syntax: UPDATE view_name SET column1=value1, column2= value2…..
WHERE CONDITION;
Example: UPDATE emp
SET name = ‘jean’
WHERE SALARY = ‘5000’;

Q.10 give advantages and disadvantages of PL/SQL

1) Advantages:
a) PL/SQL provides high performance
b) PL/SQL provides modularity
c) PL/SQL has better security
d) PL/SQL has better error handling
e) It supports object oriented programming
2) Disadvantages:
a) PL/SQL requires high amount of memory
b) It does not support functional debugging in stored procedures

Q.11 Explain indexes with its types

Indexes are special lookup tables created by a database which are then by the
database search engines to speed-up the process of data retrieval.
Indexes are used to speed-up the SELECT and WHERE clause but provide input
delay.
Indexes can be created or dropped without having an effect on the data.

Syntax of creating an index in as follows


CREATE INDEX (index_name) ON (table_name) (column1,column2..columnN);

Indexes are of 3 types


1) Simple index: this index is created on a single column.
Syntax: CREATE INDEX (index_name) on (table_name) (column1)

2) Composite index: this index can be created on multiple columns


3) Syntax: CREATE INDEX (index_name) ON (table_name)
(column1,column2..columnN);
4) Unique index: this type of index are created on selected columns but it
restricts duplicate values.
Syntax: CREATE UNIQUE INDEX (index_name) on (table_name) (column1);
When recovering the database, it must redo the effects of the previous
transactions. This is called Rolling Forward or Simple Forward Recovery. Not
all but some active transaction that didn’t complete successfully needs to
rollback, when the disk drive crashed. Such a rollback is called Backward
Recovery. The Redo Log and Rolling Forward (REDO operation) The redo log is a
set of operating system files that record all changes made to any database
buffer, including data, index, and rollback segments, whether the changes are
committed or uncommitted. The redo log protects changes made to database
buffers in memory that have not been written to the data files. The first
step of recovery from an instance or disk failure is to roll forward, or
reapply all of the changes recorded in the redo log to the data files.
Because rollback data is also recorded in the redo log, rolling forward also
regenerates the corresponding rollback segments. Rolling forward proceeds
through as many redo log files as necessary to bring the database forward in
time. Rolling forward usually includes online redo log files and may include
archived redo log files. After roll forward, the data blocks contain all
committed changes aswell as any uncommitted changes that were recorded in the
redo log. Rollback Segments and Rolling Back (UNDO operation) Rollback
segments record database actions that should be undone during certain
database operations. In database recovery, rollback segments undo the effects
of uncommitted transactions previously applied by the rolling forward phase.
After the roll forward, any changes that were not committed must be undone.
After redo log files have reapplied all changes made to the database, then
the corresponding rollback segments are used. Rollback segments are used to
identify and undo transactions that were never committed, yet were recorded
in the redo log and applied to the database during roll forward. This process
is called rolling back.
Regular backups are required to protect the database and ensure its
restoration in case of failure. Various backup types provide different
protection to our database. Backing up and restoring data is one of the most
important responsibilities of IT professionals. Three common types of
database backups can be run on a desired system: normal (full), incremental
and differential. i) Normal or Full Backups: When a normal or full backup
runs on a selected drive, all the files on that drive are backed up. This, of
course, includes system files, application files, user data — everything.
Those files are then copied to the selected destination (backup tapes, a
secondary drive or the cloud), and all the archive bits are then cleared.
Normal backups are the fastest source to restore lost data because all the
data on a drive is saved in one location. ii) Incremental Backups: A common
way to deal with the long running times required for full backups is to run
them only on weekends. Many businesses then run incremental backups
throughout the week since they take far less time. An incremental backup will
grab only the files that have been updated since the last normal backup. Once
the incremental backup has run, that file will not be backed up again unless
it changes or during the next full backup. iii) Differential Backups: An
alternative to incremental database backups that has a less complicated
restore process is a differential backup. Differential backups and recovery
are similar to incremental backups in that these backups grab only files that
have been updated since the last normal backup. However, differential backups
do not clear the archive bit. So a file that is updated after a normal backup
will be archived every time a differential backup is run until the next
normal backup runs and clears the archive bit.
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: 1. Log based recovery. 2. Shadow paging recovery 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. 2. Shadow paging recovery:
This technique is the alternative for log based recovery. In this technique,
database is divided into pages that can be stored on the disk. The page table
is used to maintain the record of location of pages. In case of database
failure, page table is used to recover the parts of database. 3. Checkpoints:
Checkpoint records all committed transactions into logs. When system fails,
it check log to determine recovery action.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy