Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Dbms important questions and answers
1. DBMS important questions and answers
1. Write about advantages of DBMS?
Minimizing redundancy: Before entering data, we are creating definitionsinwhich we are
imposing restrictions. Due to these restrictions, dbms will not allow duplicate data to be
entered. Restrictions are constraints like primary key, unique key, not null etc..
if we want only few columns data then we need not create another table. We can give access to
only those few columns to the users using views and data control language (DCL) commands. In
this way, the data is stored in only one location.
2. Eliminating redundancy: When there is no redundancy, inconsistency does not exist
3. Sharing of data: We can share the data to authorized user using DCL commands
4. Data Security: We can create users and give them username and passwords. We can grant
and revoke permissions to create session,create table etc.. We can also give access to row or
column only by using views.
5. Flexibilityof the system is improved: Due to data independence,changes in data does not
affect the application programs.
6. Data integrity: Constraints ensures data in database to be complete, correct, and consistent.
For example: By using check constraint and data types, we can ensure that numbers are not
entered in name field.By using commit command, data once stored in database will be
consistent.
7. Provides back up and recovery: due to which data once stored in database will never be lost.
2. Explain about database system environment?
Ans: The components of database are
1. Data
2. Procedures
3. Hardware
4. Software
5. People
refer notes
3. Explain about Data base models?
Hierachical data model, network data model,relational data model etc…refer notes
4. Write short notes on Data Dictionary?
A data dictionary contains metadata i.e data about the data.The users of the database normally don't
interact with the data dictionary, it is only handled by the database administrators.
The data dictionary in general contains information about the following −
Names of all the tables and their schemas.
2. Details about all the tables in the database, such as their owners, their security
constraints, when they were created etc.
Physical information about the tables such as where they are stored and how.
Table constraints such as primary key attributes, foreign key information etc.
Information about the database viewsthat are visible.
This is a data dictionary describing a table that contains employee details.
Field Name Data Type Field Size for display Description
eno Integer 10 Unique ID of each employee
Name Text 20 Name of the employee
dob Date/Time 10 DOB of Employee
phone Integer 10 Phone number of employee
5. What is Specialization?
o Specialization is a top-down approach, and it is opposite to Generalization. In
specialization, one higher level entity can be broken down into two lower level
entities.
o Specialization is used to identify the subset of an entity set that shares some
distinguishing characteristics.
o Normally, the superclass is defined first, then the subclass and its related
attributes are defined next, and then relationship between them is defined.
For example: In an Employee management system, EMPLOYEE entity can be
specialized as TESTER or DEVELOPER based on what role they play in the company.
6. Define Attribute and relationships with suitable Examples?
An attribute is a property or characteristic of an entity.An entity may contain any number of
attributes. One of the attributes is considered as the primary key. In an Entity-Relation model,
attributes are represented in an elliptical shape. Types of attributes are shown in table below
3. Attribute Type Description Symbol
Simple attribute An attribute that cannot be
divided
Composite
attribute
An attribute that can be
divided
Multivalued
attribute
The attribute which takes up
more than a single value for
each entity instance
Derived attribute An attribute that can be
derived from other attributes
Key attribute The attribute which uniquely
identifieseach entity in the
entity set
Partial Identifier
attribute
A Partial identifierattribute is
a key identifierof a weak
entity
Relationship: Any association betweentwo entity types is called a relationship. Entities take
part in the relationship.
Degree of a relationship: is the number of entitiesparticipating in the relationship.
Types of relationships based on degree
Unary Relationship Relationshipbetween
single entity
Binary Relationship Relationship between
2 entities
Ternary Relationship Relationship between
3 entities
N- ary Relationship Relationship between
N entities
Cardinality: Number of instances of one entity is associated with how many number of entities
of another entity
Types of Relationships based on cardinality
4. One-to-One A row in A is associated with only one row in B
and vice versa.
One-to-Many one row in A is associated with many rows in B.
Many-to-One many rows in A is associated with only one rows
in B.
Many-to-
Many
many rows in A is associated with many rows in
B
7. Explain domain relational calculus ?
In domain relational calculus, filteringvariable uses the domain of attributes.
Domain relational calculus uses the same operators as tuple calculus. It uses logical connectives
∧ (and), ∨ (or) and ┓ (not).
It uses Existential (∃) and Universal Quantifiers (∀) to bind the variable.
8. What is purpose of NULL value SQL?
A field with a NULL value is a field with no value. If a field in a table is optional, it is
possible to insert a new record or update a record without adding a value to this field. Then,
the field will be saved with a NULL value. A NULL value is different from a zero value or a
field that contains spaces. A field with a NULL value is one that has been left blank during
record creation!
5. To Test NULL value, we will have to use the IS NULL and IS NOT NULL operators instead.
IS NULL Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NULL;
IS NOT NULL Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
9. Explain about roll back and commit?
COMMIT command is used to permanently save any transaction into the database.
When we use any DML command like INSERT, UPDATE or DELETE, the changes made by these
commands are not permanent, until the current session is closed, the changes made by these
commands can be rolledback.
To avoid that, we use the COMMIT command to mark the changes as permanent.
Following iscommit command's syntax,
COMMIT;
ROLLBACK command restores the database to last commited state. It is also used with
SAVEPOINT command to jump to a savepoint in an ongoing transaction.
If we have used the UPDATE command to make some changes into the database, and realise
that those changes were not required, then we can use the ROLLBACK command to rollback
those changes, if they were not commited using the COMMIT command.
Following isrollback command's syntax,
ROLLBACK TO savepoint_name;
10. Define trigger and explain with suitable example?
Triggersinoracle are blocksof PL/SQL code whichoracle engine canexecute automaticallybasedon
some actionor event.
Triggersare automaticallyandrepeatedlycalleduponbyoracle engine onsatisfyingcertain
condition. If triggersare activatedthentheyare executedimplicitlybyoracle engine.
Wheneveratriggeriscreated,itcontainsthe followingthreesequential parts:
1. TriggeringEventorStatement:The statementsdue towhichatriggeroccurs.
2. TriggerRestriction:The conditionoranylimitationappliedonthe trigger.If conditionis
TRUE thentriggerfires. Notall triggershasconditions.
3. TriggerAction:The bodycontainingthe executablestatementsthatistobe executedwhen
triggerfires.
Typesof Triggers
1) Level Triggers
a) ROW LEVEL TRIGGERS: It firesforeveryrecordthatgot affected.Italwaysuse a FOREACH
ROW clause
b) STATEMENT LEVEL TRIGGERS: It firesonce foreach statementthatisexecuted.
2) EventTriggers
6. a) DDL EVENTTRIGGER: It fireswiththe executionof everyDDLstatement(CREATE,ALTER,
DROP,TRUNCATE).
b) DML EVENT TRIGGER: It fireswiththe executionof everyDMLstatement(INSERT,UPDATE,
DELETE).
c) DATABASEEVENTTRIGGER: It fireswiththe executionof everydatabase operationwhich
can be LOGON,LOGOFF,SHUTDOWN, SERVERERRORetc.
3) TimingTriggers
a) BEFORE TRIGGER: It firesbefore executingDMLstatement.
b) AFTER TRIGGER: ItfiresafterexecutingDMLstatement.
Example :Create a triggerthat firesafterinsertof everynew row inStu table.The trigger
automaticallyupdatestotal.
create or replace trigger stud_marks
after INSERT
on
Stu
for each row
begin
update Stu set total = subj1 + subj2 + subj3;
end;
/
11. a. Define file and explain about draw backs of file based system?
(Or)
b. Describe about ANSI/SPARC database architecture?
12. a. Describe generalization and specialization with suitable examples?
(Or)
b. Define ER and Explain about components of ER diagrams?
13. a. What is constraint? Explain about Key constraint with suitable examples?
(Or)
b. Describe about relational algebra with suitable examples?
Explain about DDL, DML and DCL commands with suitable Examples?
SQL is a nonprocedural query language in which the expected results is given without the
specific details about how to accomplish the task.
SQL COMMANDS
SQL contains different types of commands
DDL (Data Definition Language) Commands
DML(Data Manipulation Language) Commands
TCL(Transaction Control Language) Commands
DCL(Data Control Language) Commands
I DDL Commands: The Data Definition Languages (DDL) Commands are used to create a table
structure, modify the table structure and delete the table structure.
CREATE TABLE : The CREATE TABLE command is used to create a new table
Syntax: Create tabletablename (column_name1 data_ type (size) constraint, …);
Example:
create table student (sname varchar2(20) , rollno number(10) ,dob date );
The ALTER TABLE StatementThe ALTER TABLE statement is used to modify
structure of an existing table. There are three different syntaxes
a. ALTER TABLE ADD : This command is used to add a new column in to an
existing table syntax:
7. ALTER TABLE table_name ADD (column_name data_type(size) , …) ;
Example : alter table student add(address varchar2(20),phone_no number(10));
b. ALTER TABLE MODIFY This command is used to change the data type and size
of an existing column in to an existing table
syntax:
ALTER TABLE table_name MODIFY (old_column_name new_data_type(new_size),);
Example : alter table student modify (address varchar2(40));
c. ALTER TABLE DROP To delete a column in a table, use the following syntax
ALTER TABLE table_name DROP COLUMN column_name1,… ;
Example: alter table student drop phone_no;
DROP: This command is used to delete the structure of the table as well as records in the
relation.
Syntax :drop tabletable_name;
Ex: drop table student;
Create AS select: This is used to create a new relation or table from an existing relation or
table.
Syntax:
create tablenew_table_name (column_1, …..column_n) as select column_1, ….column_n
from old_table_name;
Ex: create table student2(sno,sname,saddress) AS select sno, name, address from student;
RENAME: command is used to rename the table.
Example: Rename student to student1;
TRUNCATING TABLE: Truncate command will delete all the records permanently in a
specified table but structure of the table will not be deleted.
• Syntax
– TRUNCATE TABLE TableName;
Eg: TRUNCATE TABLE student;
II Commands in DML:
The SQL INSERT INTO Statement: The INSERT INTO statement is used to insert new
records in a table. There are different forms of insert commands are used to insert a
records into a table.
Syntax
The first form of insert is used to insert values for all columns in a table.
INSERT INTO table_name VALUES (value1,value2,value3,...);
The second form of insert is used to insert values for some columns of a record in a table.
INSERT INTO table_name (column1,...) VALUES (value1,...);
Select: The select command is used to retrieve records from the tables.
This type is used to display the set of fields or all the fields of the selected or all records in a
table.
a. Syntax: Select * from <table_name> [WHERE condition];
Ex: select * from student;
b. Syntax: select set of fields from table_name [where condition];
Ex: selectsno,sname,addressfrom student where address=’BVRM’;
Update: The update command is used to update the content of a table.
Syntax
– UPDATE TableName SET ColumnName1=Expression1,
Ex1: update student SET total = sub1+sub2+sub3;
Ex2: UPDATE student SET total = sub1+sub2+sub3 wheresno = 10;
8. Delete: The delete command is used to delete all the records or selected records in a table.
But the structure of the table remains.
Syntax: DELETE FROM TableName;
Example 1: Delete from student;
Example 2:Delete from student where address=’BVRM’;
DCL Commands:
Two types of DCL commands are
1. Grant
2. Revoke
Grant: SQL Grant command is used to grant a privileges on the database objects to the
users.
The syntax for the GRANT command is:
GRANT privilege_name ON object_name TO user_name ;
Example: GRANT SELECT ON employee TO user1 ;
This command grants a SELECT permission on employee table to user1.
REVOKE : The revoke command removes user privileges to the database objects.
The syntax for the REVOKE command is:
REVOKE privilege_name ON object_name FROM User_name ;
For Example:
REVOKE SELECT ON employee FROM user1;
This command will revoke a SELECT privilege on employee table from user1.
Define join and Explain different types of joins in SQL?
The SQL Joins clause is used to combine records from two or more
tables in a database. A JOIN is a means for combining fields from two
tables by using values common to each.
There are different types of joins available in SQL:
INNER JOIN:
returns rows when there is a match in both tables.
LEFT JOIN:
returns all rows from the left table, even if there are no matches in the
right table.
RIGHT JOIN:
returns all rows fromthe right table, even if there are no matches in the
left table.
FULL JOIN:
returns rows when there is a match in one of the tables.
SELF JOIN:
is used to join a table to itself as if the table weretwo tables, temporarily
renaming at least one table in the SQL statement.
CARTESIAN JOIN:
returns theCartesian productof the sets of records from thetwo or more
joined tables.
Consider two tables student and course as shown below:
10. Explain about control structures of PL/SQL?
CONDITIONAL CONTROL STATEMNETS In PL/SQL there are three types of conditional
control : IF - THEN, IF-THEN-ELSE and CASE
IF – THEN Statement
This is the most basic kind of a conditional control and has the following structure
If Condition Then
Statement 1;
….
Statement 2;
End If;
The reserved word IF marks the beginning of the IF statement.
IF – THEN – ELSE
This statement enables you to specify two groups of statements One group of statements
is executed when the condition evaluates to TRUE and the other group of statements is executed
when the condition evaluates to FALSE.
If Condition Then
Statement 1;
ELSE
Statement 2;
End If;
Statement 3;
CASE:
A case statement has the following structure:
CASE SELECTOR
WHEN EXPRESSION 1 STATEMENT 1;
WHEN EXPRESSION 1 STATEMENT 1;
…..
WHEN EXPRESSION 1 STATEMENT 1;
ELSE STATEMENT N+1;
END CASE;
The reserved word CASE marks the beginning of the case statement. A selector is a value that
determines which WHEN clause should be executed.
ITERATIVE CONTROL
11. In PL/SQL there are three types of loops : Simple LOOP, WHILE loops and Numeric FOR
loop
A simple loop, as you can see from its name, is the most basic kind of loop and has the following
structure:
LOOP
STATEMENT 1;
STATEMENT 2;
…….
STATEMENT N;
END LOOP;
The reserved word LOOP marks the beginning of the simple loop. Statement 1 through N are a
sequence of statements that is executed repeatedly.
EXIT statement causes a loop to terminate when exit condition evaluates to TRUE.
LOOP
STATEMENT 1;
STATEMENT 2;
IF CONDITION THEN
EXITL;
END IF;
…….
STATEMENT N;
END LOOP;
WHILE LOOPS:
A while loop has the following structure
WHILE CONDITION LOOP
STATEMNET 1;
STATEMNET 2;
……
STATEMNET N;
End loop;
The reserved word WHILE marks the beginning of a loop construct. The word CONDITION is
the test condition of the loop that evaluates to TRUE or FALSE.
NUMERIC FOR LOOP:
A numeric FOR loop is called numeric because it requires an integer as its terminating
value. Its structure is as follows.
FOR loop_counter IN[REVERSE] Lower_limit..upper_limit LOOP
STATEMENT 1;
STATEMENT 2;
……
STATEMENT N;
END LOOP;
The reversed word FOR marks the beginning of a FOR loop construct. The variable
loop_counter is an implicitly defined index variable. There is no need to define the loop counter
in the declaration section. The values of the lower_limit and upper_limit are evaluated once for
the iteration of the loop.
Define function and Explain with suitable examples using PL/SQL?
Functions is a standalone PL/SQL subprogram. Like PL/SQL procedure, functions have a
12. unique name by which it can be referred. These are stored as PL/SQL database objects.
Procedure Vs. Function: Key Differences
Procedure Function
Used mainly to a execute certain
process
Used mainly to perform some calculation
Cannot call in SELECT statement A Function that contains no DML statements
can be called in SELECT statement
Use OUT parameter to return the
value
Use RETURN to return the value
It is not mandatory to return the value It is mandatory to return the value
RETURN will simply exit the control
from subprogram.
RETURN will exit the control from
subprogram and also returns the value
Return datatype will not be specified
at the time of creation
Return datatype is mandatory at the time of
creation
Write a PL/SQL programme to demonstrate functions.
CREATE OR REPLACE FUNCTION totalcustomers
RETURN NUMBER IS
total NUMBER(2) := 0;
BEGIN
SELECT COUNT(*) INTO total FROM emp1;
RETURN total;
END;
O/P: Function created.
To use Function:
DECLARE
c NUMBER(2);
BEGIN
c := totalcustomers();
dbms_output.put_line('Total number of customers:'||c);
END;
O/P:
Total number of customers:4
Statement processed.