Dbms Lab Manual
Dbms Lab Manual
Co-requisites:
Co-requisite of course “Database Management Systems”
Course Objectives:
Introduce ER data model, database design and normalization
Learn SQL basics for data definition and data manipulation
Course Outcomes:
Design database schema for a given application and apply normalization
Acquire skills in using SQL commands for data definition and data manipulation.
Develop solutions for database applications using procedures, cursors and triggers
LIST OF EXPERIMENTS:
1. Concept design with E-R Model
2. Relational Model
3. Normalization
6. Querying (using ANY, ALL, IN, Exists, NOT EXISTS, UNION, INTERSECT, Constraints etc.)
7. Queries using Aggregate functions, GROUP BY, HAVING and Creation and dropping of
Views.
9. Procedures
Definitions:
The cardinality ratio: - for a binary relationship specifies the maximum number of relationships
that an entity can participate in.
Weak and strong entity: - an entity set may not have sufficient attributes to form a primary key.
Such an entity set is termed a weak entity set. An entity set that has primary key is termed a
strong entity set.
Total participation:-
Ex: - if a travel agency states that every passenger must make reservation then every passenger
travels in bus. Than a passengers entity can exist only if it participates in atleast one travels
relationship instances. Thus the participation of passenger in travel is called total participation
meaning that every entity in the “total set” passenger entities must be related to bus via travels
relationship.
Specialization: in the process of identifying subsets of an entity set (the super set) that share
some distinguishing characteristics. This entity type is called the super class of the
specialization.
1. What is database?
A database is a collection of information that is organized. So that it can easily be accessed,
managed, and updated.
2. What is DBMS?
DBMS stands for Database Management System. It is a collection of programs that enables user
to create and maintain a database.
3. What is a Database system?
The database and DBMS software together is called as Database system.
4. What are the advantages of DBMS?
I. Redundancy is controlled.
II. Providing multiple user interfaces.
III. Providing backup and recovery
IV. Unauthorized access is restricted.
V. Enforcing integrity constraints.
5. What is normalization?
It is a process of analysing the given relation schemas based on their Functional Dependencies
(FDs) and primary key to achieve the properties
(1).Minimizing redundancy, (2). Minimizing insertion, deletion and update anomalies.
6. What is Data Model?
A collection of conceptual tools for describing data, data relationships data semantics and
constraints.
7. What is E-R model?
This data model is based on real world that consists of basic objects called entities and of
relationship among these objects. Entities are described in a database by a set of attributes.
8. What is Object Oriented model?
This model is based on collection of objects. An object contains values stored in instance
variables with in the object. An object also contains bodies of code that operate on the object.
These bodies of code are called methods. Objects that contain same types of values and the same
methods are grouped together into classes.
9. What is an Entity?
An entity is a thing or object of importance about which data must be captured.
10. What is DDL (Data Definition Language)?
A data base schema is specifies by a set of definitions expressed by a special language called
DDL.
11. What is DML (Data Manipulation Language)?
This language that enable user to access or manipulate data as organised by appropriate data
model. Procedural DML or Low level: DML requires a user to specify what data are needed and
how to get those data. Non-Procedural DML or High level: DML requires a user to specify what
data are needed without specifying how to get those data
12. What is DML Compiler?
It translates DML statements in a query language into low-level instruction that the query
evaluation engine can understand.
13. What is Query evaluation engine?
It executes low-level instruction generated by compiler.
14. Under what conditions should indexes be used?
Indexes can be created to enforce uniqueness, to facilitate sorting, and to enable fast retrieval by
column values. A good candidate for an index is a column that is frequently used with equal
conditions in WHERE clauses.
15. What is difference between SQL and SQL SERVER?
SQL is a language that provides an interface to RDBMS, developed by IBM. SQL SERVER is a
RDBMS just like Oracle, DB2.
WEEK: 2
Relational Model
Relational model
Represent all entities (strong, week) in tabular fashion. Represent relationships in a tabular
fashion. There are different ways of representing as tables based on the cardinality. Represent
attributes as columns in the tables or as tables based on the requirement. Different types of
attributes (composite, multivalued and derived).
Definitions:
Composite attributes: can be divided into smaller sub parts which represent more basic
attributes with independent meaning.
Multivalued attributes: for ex the attribute in the Bus entity Bustype can have different types of
buses according that the Bustype attribute contains the values as Garuda, Luxury, Express, and
Ordinary. This type of attribute is called multivalued attribute and may have lower and upper
bounds to constrain the number of values allowed for each individual entity.
Derived attributes:
In some cases, two or more attribute values are related. With the help of one attribute we get the
value of another attribute. Age and DOB attributes. With the DOB we get the age of the person
to the current date.
Relational Model concept
Relational model can represent as a table with columns and rows. Each row is known as a tuple. Each table of the
column has a name or attribute.
Attribute: It contains the name of a column in a particular table. Each attribute Ai must have a domain, dom(Ai)
Relational model can represent as a table with columns and rows. Each row is known as a tuple. Each table of the
Attribute: It contains the name of a column in a particular table. Each attribute Ai must have a domain, dom(Ai)
Relational instance: In the relational database system, the relational instance is represented by a finite set of tuples.
Relation instances do not have duplicate tuples.
Relational schema: A relational schema contains the name of the relation and name of all columns or attributes.
Relational key: In the relational key, each row has one or more attributes. It can identify the row in the relation
uniquely.
Integrity constraints
NOT NULL
UNIQUE
DEFAULT
CHECK
Key Constraints – PRIMARY KEY, FOREIGN KEY
Domain constraints
NOT NULL:
NOT NULL constraint makes sure that a column does not hold NULL value. When we don’t provide value for a
particular column while inserting a record into a table, it takes NULL value by default. By specifying NULL
constraint, we can be sure that a particular column(s) cannot have NULL values.
UNIQUE:
UNIQUE Constraint enforces a column or set of columns to have unique values. If a column has a unique constraint,
it means that particular column cannot have duplicate values in a table.
DEFAULT:
The DEFAULT constraint provides a default value to a column when there is no value provided while inserting a
record into a table.
CHECK:
This constraint is used for specifying range of values for a particular column of a table. When this constraint is being
set on a column, it ensures that the specified column must have the value falling in the specified range.
Key constraints:
PRIMARY KEY:
Primary key uniquely identifies each record in a table. It must have unique values and cannot contain nulls. In the
below example the ROLL_NO field is marked as primary key, that means the ROLL_NO field cannot have
duplicate and null values.
FOREIGN KEY:
Foreign keys are the columns of a table that points to the primary key of another table. They act as a cross-reference
between tables.
Read more about it here.
Domain constraints:
Each table has certain set of columns and each column allows a same type of data, based on its data type. The
column does not accept values of any other data type.
Company database
CREATE TABLE employee (
emp_id INT PRIMARY KEY,
first_name VARCHAR(40),
last_name VARCHAR(40),
birth_day DATE,
sex VARCHAR(10),
salary INT check(salary>0),
super_id INT,
branch_id INT);
1. What is Specialization?
It is the process of defining a set of subclasses of an entity type where each subclass contain all
the attributes and relationships of the parent entity and may have additional attributes and
relationships which are specific to itself.
2. What is generalization?
It is the process of finding common attributes and relations of a number of entities and defining a
common super class for them.
3. What is meant by Proactive, Retroactive and Simultaneous Update?
Proactive Update: The updates that are applied to database before it becomes effective in real
world.
Retroactive Update: The updates that are applied to database after it becomes effective in real
world.
Simultaneous Update: The updates that are applied to database at the same time when it becomes
effective in real world.
4. What is RAID Technology?
Redundant array of inexpensive (or independent) disks. The main goal of raid technology is to
even out the widely different rates of performance improvement of disks against those in
memory and microprocessor. Raid technology employs the technique of data striping to achieve
higher transfer rates.
5. What are serial, non serial schedule?
A schedule S is serial if, for every transaction T participating in the schedule, all the operations
of T is executed consecutively in the schedule, otherwise, the schedule is called non-serial
schedule.
Normalization
1) First Normal Form: 1NF requires that the values in each column of a table are
atomic. By atomic we mean that there are no sets of values within a column.
2) Second Normal Form: where the 1NF deals with atomicity of data, the 2NF deals
with relationships between composite key columns and non-key columns. To
achieve 2NF the tables should be in 1NF. The 2NF any non-key columns must
depend on the entire primary key.
3) Third Normal Form: 3NF requires that all columns depend directly on the primary
key. Tables violate the third normal form when one column depends an another
column, which in turn depends on the primary key(transitive dependency).
One way to identify transitive dependency is to look at your tables and see if any
columns would require updating if another column in the table was updated. If such
a column exists, it probably violates 3NF.
1NF
Relation EMPLOYEE is not in 1NF because of multi-valued attribute EMP_PHONE.
2NF
o In the second normal form, all non-key attributes are fully functional dependent on the primary key
3NF
o A relation will be in 3NF if it is in 2NF and not contain any transitive partial dependency.
o 3NF is used to reduce the data duplication. It is also used to achieve the data integrity.
o If there is no transitive dependency for non-prime attributes, then the relation must be in third normal
form.
A relation is in third normal form if it holds atleast one of the following conditions for every non-trivial function
dependency X → Y.
1. X is a super key.
2. Y is a prime attribute, i.e., each element of Y is part of some candidate key.
The above table can be converted into 3NF as follows
1. What is normalization?
It is a process of analysing the given relation schemas based on their Functional Dependencies
(FDs)
and primary key to achieve the properties
(1).Minimizing redundancy, (2). Minimizing insertion, deletion and update anomalies.
6. What is 2NF?
A relation schema R is in 2NF if it is in 1NF and every non-prime attribute A in R is fully
functionally dependent on primary key.
7. What is 3NF?
A relation schema R is in 3NF if it is in 2NF and for every FD X A either of the following is true
1. X is a Super-key of R.
2. A is a prime attribute of R.
In other words, if every non prime attribute is non-transitively dependent on primary key.
1. Partial Key:
It is a set of attributes that can uniquely identify weak entities and that are related to same
owner entity. It is sometime called as Discriminator.
2. Alternate Key:
All Candidate Keys excluding the Primary Key are known as Alternate Keys.
3. Artificial Key:
If no obvious key, either stand alone or compound is available, then the last resort is to
simply create a key, by assigning a unique number to each record or occurrence. Then this
is known as developing an artificial key.
4. Compound Key:
If no single data element uniquely identifies occurrences within a construct, then combining
multiple elements to create a unique identifier for the construct is known as creating a
compound key.
Natural Key:
When one of the data elements stored within a construct is utilized as the primary key, then
it is called the natural key.
WEEK: 4
o All the command of DDL are auto-committed that means it permanently save all the changes in the
database.
o CREATE
o ALTER
o DROP
o TRUNCATE
Syntax:
Example:
b. DROP: It is used to delete both the structure and record stored in the table.
Syntax
DROP TABLE ;
Example
c. ALTER: It is used to alter the structure of the database. This change could be either to modify the
characteristics of an existing attribute or probably to add a new attribute.
Syntax:
EXAMPLE
ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2(20));
ALTER TABLE STU_DETAILS MODIFY (NAME VARCHAR2(20));
d. TRUNCATE: It is used to delete all the rows from the table and free the space containing the table.
Syntax:
Example:
o The command of DML is not auto-committed that means it can't permanently save all the changes in the
database. They can be rollback.
o INSERT
o UPDATE
o DELETE
a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a table.
Syntax:
INSERT INTO TABLE_NAME (col1, col2, col3,.... col N) VALUES (value1, value2, value3, .... valueN);
Or
For example:
b. UPDATE: This command is used to update or modify the value of a column in the table.
Syntax:
For example:
UPDATE students
SET User_Name = 'Sonoo'
WHERE Student_Id = '3'
Syntax:
For example:
1. Procedural DML or Low level: DML requires a user to specify what data are needed and
how to get those data.
2. Non-Procedural DML or High level: DML requires a user to specify what data are needed without specifying
how to get those data.
9. What is Record-at-a-time?
The Low level or Procedural DML can specify and retrieve each record from a set of records. This
retrieve of a record is said to be Record-at-a-time.
1. Analysis phase
2. Redo Phase
3. Undo phase
IN, NOT IN operators in SQL are used with SELECT, UPDATE and DELETE
statements/queries to select, update and delete only particular records in a table those meet the
condition given in WHERE clause and conditions given in IN, NOT IN operators. I.e. it filters
records from a table as per the condition. Syntax for SQL IN & NOT IN operators are given
below.
UNION
The UNION command combines the result set of two or more SELECT statements (only distinct
values)
The following SQL statement returns the cities (only distinct values) from both the "Customers"
and the "Suppliers" table:
Example
SELECT City FROM Customers
UNION
SELECT City FROM Suppliers
ORDER BY City;
UNION ALL
The UNION ALL command combines the result set of two or more SELECT statements (allows
duplicate values).
The following SQL statement returns the cities (duplicate values also) from both the
"Customers" and the "Suppliers" table:
Example
SELECT City FROM Customers
UNION ALL
SELECT City FROM Suppliers
ORDER BY City;
Database changed
+-----+----------+-----------+--------+
+-----+----------+-----------+--------+
| 1 | rahul | hr | 10000 |
| 3 | rajat | hr | 30000 |
| 5 | rharshit | it | 50000 |
+-----+----------+-----------+--------+
+------+------+------------+-----------+
+------+------+------------+-----------+
| 1 | p1 | iot | hyd |
| 5 | p2 | android | pune |
| 4 | p3 | networking | bengalore |
| 4 | p3 | database | mangalore |
| 3 | p4 | database | mangalore |
+------+------+------------+-----------+
1) IN
The IN operator is used when you want to retrieve a column that has entries in the table or
referencing table.
Syntax
query
2) NOT IN
The NOT IN operator is used when you want to retrieve a column that has no entries in the table or
referencing table.
select * from employee where ename Not In('ramesh','mahesh','suresh');
3) ANY
The ANY operator returns true if any of the subquery values meet the condition.
Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name operator ANY
(SELECT column_name FROM table_name WHERE condition);
select * from employee where eid=ANY(select eid from project where employee.eid=project.eid);
4) All
The ALL operator returns true if all of the subquery values meet the condition.
ALL Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name operator ALL
(SELECT column_name FROM table_name WHERE condition);
UNION
The UNION operator is used to combine the result-set of two or more SELECT statements.
Each SELECT statement within UNION must have the same number of columns
The columns must also have similar data types
The columns in each SELECT statement must also be in the same order
UNION Syntax
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
Example
+------+---------+-----------+--------+
+------+---------+-----------+--------+
+------+---------+-----------+--------+
mysql> select * from emp2;
+------+--------+---------+--------+
+------+--------+---------+--------+
+------+--------+---------+--------+
mysql> select eid,ename from emp1 union select eid,ename from emp2;
mysql> select eid,ename from emp1 union all select eid,ename from emp2;
1. What is a query?
A query with respect to DBMS relates to user commands that are used to interact with a data base. The query
language can be classified into data definition language and data manipulation language.
3. What are the primitive operations common to all record management systems?
Addition, deletion and modification.
4. Name the buffer in which all the commands that are typed in are stored
‘Edit’ Buffer
9. Which part of the RDBMS takes care of the data dictionary? How
Data dictionary is a set of tables and database objects that is stored in a special area of the database and maintained
exclusively by the kernel.
13. Define SQL and state the differences between SQL and other conventional programming Languages
SQL is a nonprocedural language that is designed specifically for data access operations on normalized relational
database structures. The primary difference between SQL and other conventional programming languages is that
SQL statements specify what data operations should be performed rather than how to perform them.
14. Name the three major set of files on disk that compose a database in Oracle
There are three major sets of files on disk that compose a database. All the files are binary. These are
Database files
Control files
Redo logs
The most important of these are the database files where the actual data resides. The control files and the redo logs
support the functioning of the architecture itself.
All three sets of files must be present, open, and available to Oracle for any data on the database to be useable.
Without these files, you cannot access the database, and the database administrator might have to recover some or
all of the database using a backup, if there is one.
WEEK: 7
Aggregate functions, GROUP BY, HAVING and Creation and dropping of Views.
Create the tables in the database with different attributes insert the records in the tables and
perform the execution of the following functions
o SQL aggregation function is used to perform the calculations on multiple rows of a single
column of a table. It returns a single value.
o It is also used to summarize the data.
1. COUNT FUNCTION
o COUNT function is used to Count the number of rows in a database table. It can work on both numeric and
non-numeric data types.
o COUNT function uses the COUNT(*) that returns the count of all the rows in a specified table. COUNT(*)
considers duplicate and Null.
Syntax
COUNT(*)
or
COUNT( [ALL|DISTINCT] expression )
Examples
1) SELECT COUNT(*)
FROM PRODUCT_MAST;
2) SELECT COUNT(*)
FROM PRODUCT_MAST;
WHERE RATE>=20;
FROM PRODUCT_MAST;
2. SUM Function
Sum function is used to calculate the sum of all selected columns. It works on numeric fields only.
Syntax
SUM()
or
SUM( [ALL|DISTINCT] expression )
Example: SUM()
SELECT SUM(COST)
FROM PRODUCT_MAST;
SELECT SUM(COST)
FROM PRODUCT_MAST
WHERE QTY>3;
3. AVG function
The AVG function is used to calculate the average value of the numeric type. AVG function returns the average of
all non-Null values.
Syntax
AVG()
Example:
SELECT AVG(COST)
FROM PRODUCT_MAST;
4. MAX Function
MAX function is used to find the maximum value of a certain column. This function determines the largest value of
all selected values of a column.
Syntax
MAX()
Example:
SELECT MAX(RATE)
FROM PRODUCT_MAST;
5. MIN Function
MIN function is used to find the minimum value of a certain column. This function determines the smallest value of
all selected values of a column.
Syntax
MIN()
SELECT MIN(RATE)
FROM PRODUCT_MAST;
Group By
The MYSQL GROUP BY Clause is used to collect data from multiple records and group the result by one or more
column. It is generally used in a SELECT statement.
Syntax:
SELECT expression1, expression2, ... expression_n,
aggregate_function (expression)
FROM tables
[WHERE conditions]
GROUP BY expression1, expression2, ... expression_n;
Examples
SELECT address, COUNT(*)
FROM officers
GROUP BY address;
MySQL HAVING Clause is used with GROUP BY clause. It always returns the rows where condition is TRUE.
Syntax:
A view contains rows and columns, just like a real table. The fields in a view are fields from one
or more real tables in the database.
Example
95. Select ‘NORTH’, CUSTOMER From CUST_DTLS Where REGION = ‘N’ Order By
CUSTOMER Union Select ‘EAST’, CUSTOMER From CUST_DTLS Where REGION = ‘E’ Order By
CUSTOMER
The above is
a) Not an error
b) Error – the string in single quotes ‘NORTH’ and ‘SOUTH’
c) Error – the string should be in double quotes
d) Error – ORDER BY clause
(d) Error – the ORDER BY clause. Since ORDER BY clause cannot be used in UNIONS
12. Discuss some of the techniques that can be used to tune operational performance.
Choosing primary and secondary keys can increase the speed of row selection, joining, and row
ordering. Selecting the appropriate file organization for base tables and indexes can also improve
performance. Clustering related rows together and maintaining statistics about tables and indexes can lead to
increased efficiency.
14. What are the steps to follow when preparing to create a table?
1. Identify the data type, length, and precision for each attribute. 2. Identify the columns that can
accept a null value. 3. Identify the columns that need to be unique. 4. Identify primary and related foreign keys with
the parent table being created before the child. 5. Determine default values. 6. Determine where the domain values
are that need to be constrained. 7. Create the indexes.
Triggers are stored programs, which are automatically executed or fired when some event occurs.
Database changed
mysql> create trigger sample_insert before insert on student for each row set new.marks=new.marks+5;
+-----+-------+---------+-------+--------+
+-----+-------+---------+-------+--------+
+-----+-------+---------+-------+--------+
+-----+---------+---------------+------+-----------+
+-----+---------+---------------+------+-----------+
+-----+---------+---------------+------+-----------+
3. Describe ODBC
ODBC is a standard that contains an interface that provides a common language for application
programs to access and process SQL databases. In order to use ODBC, a driver, server name,
database name, user id, and password are required. ODBC is important for Internet applications and has gained wide
acceptance.
5. Describe some reasons that someone familiar with Microsoft Access will want to learn
VBA.
You can perform more complex functions and error handling can be accommodated by VBA. VBA code will
execute faster since code runs faster than macros and maintenance is easier because VBA modules are stored with
the forms and reports. Reading VBA is easier because you can see the entire code. Finally, you can pass parameters
and use OLE automation better.
15. Describe the differences between a data warehouse and data mart.
A data warehouse is for the enterprise and contains multiple subjects. A data mart is for a specific
functional area and focuses on one subject. A data warehouse is flexible and data-oriented and
contains detailed historical data. A data mart is restrictive and project-oriented and contains some historical data.
21. Describe the difference between homogeneous and heterogeneous distributed database.
A homogenous database is one that uses the same DBMS at each node. Either each node can work
independently or a central DBMS may coordinate database activities. A heterogeneous database is one that may
have a different DBMS at each node. It may support some or all of the functionality of one logical database. It may
support full Distributed DBMS functionality or partial Distributed DBMS functionality.
WEEK 9
PROCEDURES
The PL/SQL stored procedure or simply a procedure is a PL/SQL block which performs one or more specific tasks. It
is just like procedures in other programming languages.
mysql> delimiter /
-> begin
-> end;
-> /
+-----+---------+---------------+------+-----------+
+-----+---------+---------------+------+-----------+
-> begin
-> end;
-> /
+-----+---------+
| did | dname |
+-----+---------+
| 1 | ramesh |
| 2 | jogit |
| 3 | gupta |
| 4 | atmaram |
+-----+---------+
-> end;
-> /
+-----+-------+--------------+------+-----------+
+-----+-------+--------------+------+-----------+
+-----+-------+--------------+------+-----------+
+-----+---------+----------+------+-----------+
+-----+---------+----------+------+-----------+
+-----+---------+----------+------+-----------+
-> begin
-> end;
-> /
Query OK, 0 rows affected (0.01 sec)
+-----+---------+-----------+
+-----+---------+-----------+
| 1 | ramesh | hyderabad |
| 2 | jogit | hyderabad |
| 3 | gupta | hyderabad |
| 4 | atmaram | hyderabad |
+-----+---------+-----------+
One-to-one: Single table having drawn relationship with another table having similar kind of columns.
One-to-many: Two tables having primary and foreign key relation.
Many-to-many: Junction table having many tables related to many tables.
6) Define Normalization.
Organized data void of inconsistent dependency and redundancy within a database is called normalization.
No duplicate entries
Saves storage space
Boasts the query performances.
Boosting up database performance, adding of redundant data which in turn helps rid of complex data is called
denormalization.
8) Define DDL and DML.
Manipulating data in a database such as inserting, updating, deleting is defined as Data Manipulation Language.
(DML)
Full recordings of two tables is Union All operator.A distinct recording of two tables is Union.
USAGE OF CURSORS
Cursors In MySQL, a cursor allows row-by-row processing of the result sets. A cursor is used for
the result set and returned from a query. By using a cursor, you can iterate, or by step through the
results of a query and perform certain operations on each row. The cursor allows you to iterate
through the result set and then perform the additional processing only on the rows that require it.
In a cursor contains the data in a loop. Cursors may be different from SQL commands that
operate on all the rows in the returned by a query at one time.
Declare a cursor
+------+--------+------+-------+
+------+--------+------+-------+
| 1 | ravi | 15 | 25 |
| 2 | ramu | 20 | 30 |
| 2 | rahul | 18 | 26 |
| 5 | kiran | 19 | 28 |
| 6 | varun | 21 | 32 |
| 8 | ramesh | 22 | 33 |
| 8 | rohit | 10 | 20 |
+------+--------+------+-------+
-> begin
-> declare c1 cursor for select sid,sname from students where sid=in_customer_id;
-> std:LOOP
-> end;
-> $$
+---------------------+
| concat(v_id,v_name) |
+---------------------+
| 2ramu |
+---------------------+
+---------------------+
| concat(v_id,v_name) |
+---------------------+
| 2rahul |
+---------------------+
+---------------------+
| concat(v_id,v_name) |
+---------------------+
| 1ravi |
+---------------------+
+---------------------+
| concat(v_id,v_name) |
+---------------------+
| 5kiran |
+---------------------+
+---------------------+
| concat(v_id,v_name) |
+---------------------+
| 6varun |
+---------------------+
Compilation process includes syntax check, bind and p-code generation processes.
Syntax checking checks the PL SQL codes for compilation errors. When all errors are corrected, a storage address is
assigned to the variables that hold data. It is called Binding. P-code is a list of instructions for the PL SQL engine. P-
code is stored in the database for named blocks and is used the next time it is executed.
A syntax error can be easily detected by a PL/SQL compiler. For eg, incorrect spelling.
A runtime error is handled with the help of exception-handling section in an PL/SQL block. For eg, SELECT INTO
statement, which does not return any rows.
Other users can see the data changes made by the transaction.
The locks acquired by the transaction are released.
The work done by the transaction becomes permanent.
A ROLLBACK statement gets issued when the transaction ends, and the following is true.
It undoes all the work done by the user in a transaction. With SAVEPOINT, only part of transaction can be undone.
A cursor is implicit by default. The user cannot control or process the information in this cursor.
If a query returns multiple rows of data, the program defines an explicit cursor. This allows the application to
process each row sequentially as the cursor returns it.
It occurs when a trigger tries to update a row that it is currently using. It is fixed by using views or temporary tables,
so database selects one and updates the other.
DECLARE statement is used by PL SQL anonymous blocks such as with stand alone, non-stored procedures. If it is
used, it must come first in a stand alone file.
7) How many triggers can be applied to a table?
SQLCODE returns the value of the number of error for the last encountered error whereas SQLERRM returns the
message for the last error.
Cursor_Already_Open
Invaid_cursor
var:=NVL(var2,'Hi');
IS NULL and IS NOT NULL can be used to check specifically to see whether the value of a variable is NULL or
not.
No, SQL*Plus does not have a PL/SQL Engine embedded in it. Thus, all PL/SQL code is sent directly to database
engine. It is much more efficient as each statement is not individually stripped off.
INITCAP, UPPER, SUBSTR, LOWER and LENGTH are all character functions. Group functions give results
based on groups of rows, as opposed to individual rows. They are MAX, MIN, AVG, COUNT and SUM.
16) Explain TTITLE and BTITLE.
TTITLE and BTITLE commands that control report headers and footers.
%FOUND : Checks if the cursor has fetched any row. It is true if rows are fetched
%NOT FOUND : Checks if the cursor has fetched any row. It is True if rows are not fetched.
Intersect is the product of two tables and it lists only matching rows.
Sequences are used to generate sequence numbers without an overhead of locking. Its drawback is that the sequence
number is lost if the transaction is rolled back.
20) How would you reference column values BEFORE and AFTER you have inserted and deleted triggers?
Using the keyword "new.column name", the triggers can reference column values by new collection. By using the
keyword "old.column name", they can reference column vaues by old collection.
SYSDATE refers to the current server system date. It is a pseudo column. USER is also a pseudo column but refers
to current user logged onto the session. They are used to monitor changes happening in the table.
ROWID is the logical address of a row, it is not a physical column. It composes of data block number, file number
and row number in the data block. Thus, I/O time gets minimized retrieving the row, and results in a faster query.
Database links are created in order to form communication between various databases, or different environments
like test, development and production. The database links are read-only to access other information as well.