Professional Documents
Culture Documents
Part-A:
1. Differentiate the file processing system with DBMS. (Nov/Dec-16)
File Processing System Database Management System
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
Example:
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));
10. Give example for one to one and one to many relationships. (Nov/Dec-2018)
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’;
17. Differentiate between Dynamic SQL and Static SQL. (Nov/Dec-14,15,16, Apr/May-15)
STATIC (EMBEDDED) SQL DYNAMIC (INTERACTIVE) SQL
SQL statements are compiled at compile SQL statements are compiled at run
time. time.
It is generally used for situations where It is generally used for situations where
data is distributed uniformly. data is distributed non uniformly.
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:
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)
Table created.
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.
STUD_NAME VARCHAR2(20)
STUD_ID VARCHAR2(10)
DOB DATE
BRANCH VARCHAR2(5)
STUD_ADDR VARCHAR2(20)
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.
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.
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
1 row created.
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.
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.
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’.
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
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;
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;
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:
SQL statements are compiled at compile SQL statements are compiled at run
time. time.
It is generally used for situations where It is generally used for situations where
data is distributed uniformly. data is distributed non uniformly.