You are on page 1of 21

CS8492 - DATABASE MANAGEMENT SYSTEMS

UNIT I RELATIONAL DATABASES 10


Purpose of Database System – Views of data – Data Models – Database System Architecture –
Introduction to relational databases – Relational Model – Keys – Relational Algebra – SQL fundamentals –
Advanced SQL features – Embedded SQL– Dynamic SQL.

Part-A:
1. Differentiate the file processing system with DBMS. (Nov/Dec-16)
File Processing System Database Management System

A database is generally used for storing


A file system is a more unstructured data
related, structured data, with well defined data
store for storing arbitrary, probably
formats, in an efficient manner for insert,
unrelated data.
update and/or retrieval.

A file system provides much looser While databases are consistent at any instant in
guarantees about consistency, isolation time, provide, isolated transactions and durable
and durability. writes

A database management system coordinates


A file-processing system coordinates only
both the physical and the logical access to the
the physical access to the data.
data

A file-processing system is designed to


A database management system is designed to
allow predetermined access to data (i.e.
allow flexible access to data (i.e. queries)
compiled programs)

Unauthorized access cannot be restricted


Unauthorized access is restricted in DBMS
in File processing system

Redundancy cannot be controlled in File


Redundancy can be controlled in DBMS
processing system.

2. With a neat diagram of a DBMS. (May/June-16)


3. Distinguish between key and super key. (Apr/May-2017)
A super key (SK) is a set of attributes that uniquely identifies the tuples of a relation. It satisfies the
uniqueness constraint. All super keys can’t be candidate keys but its reverse is true. In a relation,
numbers of super keys are more than number of candidate keys.
A key (K) is an attribute or set of attributes that uniquely identifies the tuples of a relation.

4. Define a foreign key. Give example. (Apr/May-2018)


A foreign key is a column or group of columns in a relational database table that provides a link
between data in two tables. It acts as a cross-reference between tables because it references the
primary key of another table, thereby establishing a link between them.

Example:

Consider the structure of the following two tables.

CUSTOMERS table:
CREATE TABLE CUSTOMERS(ID INT NOT NULL, NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL, ADDRESS CHAR (25) , SALARY DECIMAL (18, 2),
PRIMARY KEY (ID));
ORDERS table:
CREATE TABLE ORDERS (ID INT NOT NULL, DATE DATETIME,
CUSTOMER_ID INT references CUSTOMERS(ID), AMOUNT double, PRIMARY KEY (ID));

5. What is data definition language? Give example. (Apr/May-2018)


DDL or Data Definition Language actually consists of the SQL commands that can be used to
define the database schema. It simply deals with descriptions of the database schema and is used to
create and modify the structure of database objects in the database.

Examples of DDL commands:


 CREATE – is used to create the database or its objects (like table, index, function, views, store
procedure and triggers).
 DROP – is used to delete objects from the database.
 ALTER-is used to alter the structure of the database.
 TRUNCATE–is used to remove all records from a table, including all spaces allocated for the
records are removed.
 COMMENT –is used to add comments to the data dictionary.
 RENAME –is used to rename an object existing in the database.

6. State the levels of abstraction in a DBMS. (Nov/Dec-2017)


There are mainly three levels of data abstraction: Internal Level: Actual PHYSICAL
storage structure and access paths. Conceptual or Logical Level: Structure and constraints for the
entire database. External or View level: Describes various user views.
7. What are the problems caused by redundancy? (Nov/Dec-2017)
Redundancy means having multiple copies of same data in the database. This problem arises when a
database is not normalized. Problems caused due to redundancy are:
 Insertion Anomaly
 Deletion Anomaly
 Updation Anomaly

8. State the steps in query processing. (Nov/Dec-2017)


Query Processing would mean the entire process or activity which involves query
translation into low level instructions, query optimization to save resources, cost estimation or
evaluation of query, and extraction of data from the database.
Step 1: Parsing
Step 2: Translation
Step 3: Optimizer
Step 4: Execution Plan
Step 5: Evaluation

9. Mention some of the major responsibilities of a database administrator. (Nov/Dec-2018)


Database administrators (DBAs) use specialized software to store and organize data.
The responsibilities may include capacity planning, installation, configuration, database design,
migration, performance monitoring, security, troubleshooting, as well as backup and data recovery.

10. Give example for one to one and one to many relationships. (Nov/Dec-2018)

11. What is the purpose of Database Management System? (Nov/Dec-2014)


It is a collection of programs that enables the user to create and maintain a database. In other words,
it is general-purpose software that provides the users with the processes of
defining, constructing and manipulating the database for various applications.The following are the
main disadvantages of File Processing system:

 Data redundancy and inconsistency.


 Difficult in accessing data.
 Data isolation.
 Data integrity.
 Concurrent access is not possible.
 Security Problems.
12. Define: DDL, DML, DCL and TCL. (Apr/May-15)
DDL(Data Definition Language) : DDL or Data Definition Language actually consists of the SQL
commands that can be used to define the database schema. It simply deals with descriptions of the
database schema and is used to create and modify the structure of database objects in the database.
DDL Commands: create, drop, alter, truncate, comment, rename
DQL (Data Query Language): DML statements are used for performing queries on the data
within schema objects. The purpose of DQL Command is to get some schema relation based on the
query passed to it.
DQL Commands: select
DML (Data Manipulation Language) : The SQL commands that deals with the manipulation of
data present in the database belong to DML or Data Manipulation Language and this includes most
of the SQL statements.
DML Commands: insert, update, delete
TCL (transaction Control Language) : TCL commands deals with the transaction within the
database.
TCL Commands: grant, revoke

13. Name the categories of SQL command. (May/June-16)

14. What are aggregate functions? And list the aggregate functions supported by SQL?( Nov/Dec-
2018)
In database management 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.
Various Aggregate Functions:
1) Count()
2) Sum()
3) Avg()
4) Min()
5) Max()

15. Write a SQL statement to find the names and loan numbers of all customers who have a loan
at XYZ branch. (Nov/Dec-2018)
select customer_name, loan_number from loan
where branch_name = ‘Chennai’;

16. What is view? How can it be created? Explain with an example.(May/June-16)


View is one of the database objects in SQL. It logically represents subsets of data from one
or more table. We can presents logical subset of data by creating views of tables. A view is a logical
table based on table or another view. A view is a window of table .View always depends on base
table. The view is stored as SELECT statement in data dictionary.
Advantages:
 To restrict data access.
 To make complex query easy.
 To provide data independencies.
 To represents different views of same data.
Example/Query:
CREATE VIEW sal5
AS SELECT employee_id ID_NUMBER, last_name NAME , salary*12 ANN_SALARY
FROM emp
WHERE dept_id=50;

17. Differentiate between Dynamic SQL and Static SQL. (Nov/Dec-14,15,16, Apr/May-15)
STATIC (EMBEDDED) SQL DYNAMIC (INTERACTIVE) SQL

In Static SQL, how database will be


In Dynamic SQL, how database will be
accessed is predetermined in the
accessed is determined at run time.
embedded SQL statement.

It is more speedy and efficient. It is less speedy and efficient.

SQL statements are compiled at compile SQL statements are compiled at run
time. time.

Parsing, Validation, Optimization and Parsing, Validation, Optimization and


Generation of application plan are done Generation of application plan are
at compile time. done at run time.

It is generally used for situations where It is generally used for situations where
data is distributed uniformly. data is distributed non uniformly.

EXECUTE IMMEDIATE, EXECUTE EXECUTE IMMEDIATE, EXECUTE


and PREPARE statements are not used. and PREPARE statements are used.

It is less flexible. It is more flexible.

18. State the need for Query Optimization. (Apr/May-15)


The goal of query optimization is to reduce the system resources required to fulfil a query, and
ultimately provide the user with the correct result set faster.
 Query Optimization provides the user with faster results, which makes the application
seem faster to the user.
 It allows the system to service more queries in the same amount of time, because each
request takes less time than unoptimized queries.
 It ultimately reduces the amount of wear on the hardware (e.g. disk drives), and allows
the server to run more efficiently (e.g. lower power consumption, less memory usage).

19. Why does SQL allow duplicate tuples in a table or in a query results? (Nov/Dec-15)
By default query result and table allow duplicate records. SELECT returns data according to
WHERE filter (or all data, if it is omitted). It simply checks WHERE conditions for each rows.
If table has duplicates and they comply with WHERE clause, the rows are selected. You can add
DISTINCT to avoid duplicates. Duplicated rows in tables can be restricted with UNIQUE keys.
Part-B:

1. With a neat diagram, explain the basic architecture of a DBMS.(Nov/Dec-15,May/June-16)

Database Users:
Users are differentiated by the way they expect to interact with the system:
 Application programmers:
o Application programmers are computer professionals who write application programs.
Application programmers can choose from many tools to develop user interfaces.
o Rapid application development (RAD) tools are tools that enable an application programmer
to construct forms and reports without writing a program.
 Sophisticated users:
o Sophisticated users interact with the system without writing programs. Instead, they form
their requests in a database query language.
o They submit each such query to a query processor, whose function is to break down DML
statements into instructions that the storage manager understands.
 Specialized users :
o Specialized users are sophisticated users who write specialized database applications that do
not fit into the traditional data-processing framework.
o Among these applications are computer-aided design systems, knowledge base and expert
systems, systems that store data with complex data types (for example, graphics data and
audio data), and environment-modeling systems.
 Naïve users :
o Naive users are unsophisticated users who interact with the system by invoking one of the
application programs that have been written previously.
o For example, a bank teller who needs to transfer $50 from account A to account B invokes a
program called transfer. This program asks the teller for the amount of money to be
transferred, the account from which the money is to be transferred, and the account to which
the money is to be transferred.

Database Administrator:

 Coordinates all the activities of the database system. The database administrator has a good
understanding of the enterprise’s information resources and needs.
 Database administrator's duties include:
o Schema definition: The DBA creates the original database schema by executing a set of
data definition statements in the DDL.
o Storage structure and access method definition.
o Schema and physical organization modification: The DBA carries out changes to the
schema and physical organization to reflect the changing needs of the organization, or to
alter the physical organization to improve performance.
o Granting user authority to access the database: By granting different types of
authorization, the database administrator can regulate which parts of the database various
users can access.
o Specifying integrity constraints.
o Monitoring performance and responding to changes in requirements.

Query Processor:
The query processor will accept query from user and solves it by accessing the database.
Parts of Query processor:
 DDL interpreter
This will interprets DDL statements and fetch the definitions in the data dictionary.
 DML compiler
a. This will translates DML statements in a query language into low level instructions that the query
evaluation engine understands.
b. A query can usually be translated into any of a number of alternative evaluation plans for same
query result DML compiler will select best plan for query optimization.
 Query evaluation engine
This engine will execute low-level instructions generated by the DML compiler on DBMS.
Storage Manager/Storage Management:

 A storage manager is a program module which acts like interface between the data stored in a
database and the application programs and queries submitted to the system.
 Thus, the storage manager is responsible for storing, retrieving and updating data in the database.
 The storage manager components include:
o Authorization and integrity manager: Checks for integrity constraints and authority of
users to access data.
o Transaction manager: Ensures that the database remains in a consistent state although
there are system failures.
o File manager: Manages the allocation of space on disk storage and the data structures used
to represent information stored on disk.
o Buffer manager: It is responsible for retrieving data from disk storage into main memory.
It enables the database to handle data sizes that are much larger than the size of main
memory.
o Data structures implemented by storage manager.
o Data files: Stored in the database itself.
o Data dictionary: Stores metadata about the structure of the database.
o Indices: Provide fast access to data items.

2. Explain the catalog information for cost estimation for selection and sorting operation in
database. (Nov/Dec-17)
3. Write the DDL, DML, DCL commands for the students database. Which contains student
details: name, id, DOB, branch. Course details: Course name, Course id, Stud id, Faculty
name, marks. (Nov/Dec-17)
DDL Commands:

1. Create
Syntax:
Create table tablename(column_name1 datatype(size), column_name2
datatype(size), column_name3 datatype(size),………);
Example:
SQL> Create table Student(Stud_name varchar2(20), Stud_id varchar2(10),
DOB date, branch varchar2(5));

Table created.
SQL> desc Student;
Name Null? Type
-----------------------------------------------------------------------------

STUD_NAME VARCHAR2(20)
STUD_ID VARCHAR2(10)
DOB DATE
BRANCH VARCHAR2(5)

SQL> Create table Course(course_name varchar2(20), course_id varchar2(5),


Stud_id varchar2(10), faculty_name varchar2(15), mark1 number(3), mark2
number(3), mark3 number(3));

Table created.

SQL> desc Course;


Name Null? Type
-----------------------------------------------------------------------------

COURSE_NAME VARCHAR2(20)
COURSE_ID VARCHAR2(5)
STUD_ID VARCHAR2(10)
FACULTY_NAME VARCHAR2(15)
MARK1 NUMBER1(3)
MARK2 NUMBER2(3)
MARK3 NUMBER3(3)

2. Alter table
Syntax:
Alter table tablename add(column_name datatype(size));
Alter table tablename modify(column_name datatype(size));

Example:
SQL> Alter table Student add(Stud_addr varchar2(20));

Table altered.

SQL> desc Student;


Name Null? Type
-----------------------------------------------------------------------------

STUD_NAME VARCHAR2(20)
STUD_ID VARCHAR2(10)
DOB DATE
BRANCH VARCHAR2(5)
STUD_ADDR VARCHAR2(20)

SQL> Alter table Course modify(course_id number(7));

Table altered.
SQL> desc Course;
Name Null? Type
-----------------------------------------------------------------------------

COURSE_NAME VARCHAR2(20)
COURSE_ID VARCHAR2(7)
STUD_ID VARCHAR2(10)
FACULTY_NAME VARCHAR2(15)
MARK1 NUMBER1(3)
MARK2 NUMBER2(3)
MARK3 NUMBER3(3)

3. Truncate Table
Syntax:
Truncate table tablename;

Example:
SQL> Truncate table Student;

Table truncated.

SQL> desc Student;


Name Null? Type
-----------------------------------------------------------------------------

STUD_NAME VARCHAR2(20)
STUD_ID VARCHAR2(10)
DOB DATE
BRANCH VARCHAR2(5)
STUD_ADDR VARCHAR2(20)

4. Drop Table
Syntax:
Drop table tablename;

Example:
SQL> Drop table Student;

Table dropped.

SQL> desc Student;


ERROR:
ORA-04043: object Student does not exist

DML Commands:
1. Insert
Syntax:
Insert into tablename values(‘&column_name1’, ‘&column_name1’,
‘&column_name1’,…..);

Example:
SQL> insert into Student values('&stud_name', '&stud_id', '&DOB', '&branch',
'&stud_addr');
Enter value for stud_name: Ram
Enter value for stud_id: MECH101
Enter value for DOB: 25-05-1995
Enter value for branch: MECH
Enter value for stud_addr: Salem

old 1: Insert into Student values('&stud_name', '&stud_id', '&DOB', '&branch',


'&stud_addr')
new 1: Insert into Student values('Ram', 'MECH101', '25-05-1995', 'MECH', 'Salem')

1 row created.

SQL> insert into Course values('&course_name', '&course_id', '&stud_id', '&faculty


_name', '&mark1', '&mark2', '&mark3' );
Enter value for course_name: ENGG
Enter value for course_id: MECH3
Enter value for stud_id: MECH120
Enter value for faculty_name: Mani K
Enter value for mark1: 89
Enter value for mark2: 76
Enter value for mark3: 95

old 1: Insert into Course values('&course_name', '&course_id', '&stud_id',


'&faculty_name', '&mark1', '&mark2', '&mark3')
new 1: Insert into Course values('ENGG', 'MECH3', 'MECH120', 'Mani K', '89', '76', '95')

1 row created.

2. Select Command
Syntax:
Select * from tablename;

Example:
SQL> select * from Student;

3. Update Command:

Syntax:
Update table tablename set column_name=’value’ where condition;

Example:
SQL> Update Student set stud_id='MECH109' where stud_name='Sarath';
1 row updated.
SQL> select * from Student;

4. Delete Command:

Syntax:
Delete from tablename where condition;

Example:
SQL> Delete from Course where stud_id='CSE103';

1 row deleted.

SQL> select * from Course;


DCL Commands:
In DCL we have two commands,
 GRANT: Used to provide any user access privileges or other priviliges for the database.
 REVOKE: Used to take back permissions from any user.

Grant all privilege to a User:


sysdba is a set of priviliges which has all the permissions in it. So if we want to provide all the
privileges to any user, we can simply grant them the sysdba permission.
GRANT sysdba TO username

Example: GRANT sysdba TO Mathi

Grant permission to create any table:


Sometimes user is restricted from creating come tables with names which are reserved for system
tables. But we can grant privileges to a user to create any table using the below command,
GRANT CREATE Course TO Mathi

Grant permission to drop any table:


As the title suggests, if you want to allow user to drop any table from the database, then grant this
privilege to the user,
GRANT DROP Student TO Mathi

To take back Permissions:


And, if you want to take back the privileges from any user, use the REVOKE command.
REVOKE CREATE TABLE FROM username

Example: REVOKE CREATE TABLE FROM Mathi

4. Explain select, project, Cartesian product and join operations in relational algebra with an
example. (Apr/May-2018)

Relational Algebra is procedural query language, which takes Relation as input and generates
relation as output. Relational algebra mainly provides theoretical foundation for relational databases
and SQL.
Operators in Relational Algebra:
1) Projection (π)
Projection is used to project required column data from a relation.
Example :
R
(A B C)
----------
1 2 4
2 2 3
3 2 3
4 3 4
π (BC)
B C
-----
2 4
2 3
3 4
Note: By Default projection removes duplicate data.
2) Selection (σ)
Selection is used to select required tuples of the relations. for the above relation
σ (c>3)R
will select the tuples which have c more than 3.
Note: selection operator only selects the required tuples but does not display them. For displaying, data
projection operator is used.
For the above selected tuples, to display we need to use projection also.
π (σ (c>3)R ) will show following tuples.
A B C
-------
1 2 4
4 3 4

3) Union (U)
Union operation in relational algebra is same as union operation in set theory, only constraint is for
union of two relation both relation must have same set of Attributes.

4) Set Difference (-)


Set Difference in relational algebra is same set difference operation as in set theory with the
constraint that both relation should have same set of attributes.

5) Rename (ρ)
Rename is a unary operation used for renaming attributes of a relation.
ρ (a/b)R will rename the attribute ‘b’ of relation by ‘a’.

6) Cross Product (X)


Cross product between two relations let say A and B, so cross product between A X B will results all
the attributes of A followed by each attribute of B. Each record of A will pairs with every record of B.
Example:
A B
(Name Age Sex ) (Id Course)
------------------ -------------
Ram 14 M 1 DS
Sona 15 F 2 DBMS
kim 20 M
A X B
Name Age Sex Id Course
---------------------------------
Ram 14 M 1 DS
Ram 14 M 2 DBMS
Sona 15 F 1 DS
Sona 15 F 2 DBMS
Kim 20 M 1 DS
Kim 20 M 2 DBMS
Note: if A has ‘n’ tuples and B has ‘m’ tuples then A X B will have ‘n*m’ tuples.

7) Natural Join (⋈)


Natural join is a binary operator. Natural join between two or more relations will result set of all
combination of tuples where they have equal common attribute.
Example:
Emp Dep
(Name Id Dept_name ) (Dept_name Manager)
------------------------ ---------------------
A 120 IT Sale Y
B 125 HR Prod Z
C 110 Sale IT A
D 111 IT

Emp ⋈ Dep
Name Id Dept_name Manager
-------------------------------
A 120 IT A
C 110 Sale Y
D 111 IT A
8) Conditional Join
Conditional join works similar to natural join. In natural join, by default condition is equal between
common attribute while in conditional join we can specify the any condition such as greater than, less
than, not equal.
Example:
R S
(ID Sex Marks) (ID Sex Marks)
------------------ --------------------
1 F 45 10 M 20
2 F 55 11 M 22
3 F 60 12 M 59
Join between R And S with condition R.marks >= S.marks

R.ID R.Sex R.Marks S.ID S.Sex S.Marks


-----------------------------------------------
1 F 45 10 M 20
1 F 45 11 M 22
2 F 55 10 M 20
2 F 55 11 M 22
3 F 60 10 M 20
3 F 60 11 M 22
3 F 60 12 M 59

5. What is query optimization? Outline the steps in query optimization. (Apr/May-2018)


Query Processing
Query Processing would mean the entire process or activity which involves query translation into
low level instructions, query optimization to save resources, cost estimation or evaluation of query,
and extraction of data from the database.

Goal: To find an efficient Query Execution Plan for a given SQL query which would minimize the
cost considerably, especially time.

Cost Factors: Disk accesses [which typically consumes time], read/write operations [which
typically needs resources such as memory/RAM].

The major steps involved in query processing are depicted in the figure below;

Let us consider the following two relations as the example tables for our discussion;

Employee(Eno, Ename, Phone)


Proj_Assigned(Eno, Proj_No, Role, DOP)
where,
Eno is Employee number,
Ename is Employee name,
Proj_No is Project Number in which an employee is assigned,
Role is the role of an employee in a project,
DOP is duration of the project in months.
With this information, let us write a query to find the list of all employees who are working in a
project which is more than 10 months old.

SELECT Ename
FROM Employee, Proj_Assigned
WHERE Employee.Eno = Proj_Assigned.Eno AND DOP > 10;
Input:
A query written in SQL is given as input to the query processor. For our case, let us consider the
SQL query written above.
Step 1: Parsing
In this step, the parser of the query processor module checks the syntax of the query, the user’s
privileges to execute the query, the table names and attribute names, etc. The correct table names,
attribute names and the privilege of the users can be taken from the system catalog (data
dictionary).
Step 2: Translation
If we have written a valid query, then it is converted from high level language SQL to low level
instruction in Relational Algebra.
For example, our SQL query can be converted into a Relational Algebra equivalent as follows;
πEname(σDOP>10 Λ Employee.Eno=Proj_Assigned.Eno(Employee X Prof_Assigned))
Step 3: Optimizer
Optimizer uses the statistical data stored as part of data dictionary. The statistical data are
information about the size of the table, the length of records, the indexes created on the table, etc.
Optimizer also checks for the conditions and conditional attributes which are parts of the query.
Step 4: Execution Plan
A query can be expressed in many ways. The query processor module, at this stage, using the
information collected in step 3 to find different relational algebra expressions that are equivalent
and return the result of the one which we have written already.
For our example, the query written in Relational algebra can also be written as the one given below;

πEname(Employee ⋈Eno (σDOP>10 (Prof_Assigned)))


So far, we have got two execution plans. Only condition is that both plans should give the same
result.
Step 5: Evaluation
Though we got many execution plans constructed through statistical data, though they return same
result (obvious), they differ in terms of Time consumption to execute the query, or the Space
required executing the query. Hence, it is mandatory choose one plan which obviously consumes
less cost.
At this stage, we choose one execution plan of the several we have developed. This Execution plan
accesses data from the database to give the final result.
In our example, the second plan may be good. In the first plan, we join two relations (costly
operation) then apply the condition (conditions are considered as filters) on the joined relation. This
consumes more time as well as space.
In the second plan, we filter one of the tables (Proj_Assigned) and the result is joined with the
Employee table. This join may need to compare less number of records. Hence, the second plan is
the best (with the information known, not always).

6. Explain static and dynamic SQL in detail.


Static or Embedded SQL are SQL statements in an application that do not change at runtime and,
therefore, can be hard-coded into the application.

Dynamic SQL is SQL statements that are constructed at runtime; for example, the application may
allow users to enter their own queries.
Dynamic SQL is a programming technique that enables you to build SQL statements dynamically at
runtime.
 You can create more general purpose, flexible applications by using dynamic SQL because
the full text of a SQL statement may be unknown at compilation.
 Using Static SQL has a benefit which is the optimization of the statement that results an
application with high performance as it offers a good flexibility better than Dynamic SQL.
 Since access plans for dynamic statements are generated at run-time so they must be
prepared in the application, and this is something you will never look at in the static SQL,
but these are not the only differences between them.
 So we can say that dynamic SQL has only one advantage over static statements which can
be clearly noticed once the application is edited or upgraded,
 With Dynamic statements there’s no need for pre-compilation or re-building as long as the
access plans are generated at run-time, whereas static statements require regeneration of
access plans if they were modified, in addition to the fact that Dynamic SQL requires more
permissions
 It also might be a way to execute unauthorized code, we don’t know what kind of users
we’ll have, so for security it can be dangerous if the programmer didn’t handle it.

The basic differences between Static or Embedded and Dynamic or Interactive SQL:

STATIC (EMBEDDED) SQL DYNAMIC (INTERACTIVE) SQL

In Static SQL, how database will be


In Dynamic SQL, how database will be
accessed is predetermined in the
accessed is determined at run time.
embedded SQL statement.

It is more speedy and efficient. It is less speedy and efficient.

SQL statements are compiled at compile SQL statements are compiled at run
time. time.

Parsing, Validation, Optimization and Parsing, Validation, Optimization and


Generation of application plan are done Generation of application plan are
at compile time. done at run time.

It is generally used for situations where It is generally used for situations where
data is distributed uniformly. data is distributed non uniformly.

EXECUTE IMMEDIATE, EXECUTE EXECUTE IMMEDIATE, EXECUTE


and PREPARE statements are not used. and PREPARE statements are used.

It is less flexible. It is more flexible.

Limitation of Dynamic SQL:


We cannot use some of the SQL statements Dynamically.
Performance of these statements is poor as compared to Static SQL.
Limitations of Static SQL:
They do not change at runtime thus are hard-coded into applications.

You might also like