Mindmajix
Mindmajix
Mindmajix
Reporting Tools Various tools available to analyze Unavailability of tools to analyze data and
the performance performance
Development model Fine-grained database model Architects can create new DB models
Database Examples Postgres, SQLite, Oracle, etc., BigTable, Cassandra, MongoDB, etc.,
Type of Data storage Not suitable for hierarchical data Best suitable for hierarchical data.
storage
Q2) What do you know about a Database Management system?
Ans: It is basically a program which is considered when it comes to maintaining,
creating, deploying, controlling as well as monitoring the use of a database. It can
also be considered as a file manager which is good enough to be trusted for
managing the data kept in a database than a file system.
The database approach is really a good one as it is numerous benefits for the
organizations. The entire data can easily be managed simply irrespective of its size
and complexity.
Q3)What do you mean by Fields and Tables and how they are useful?
Ans: Basically, a table is a set of different rows and columns and is organized in a
model. The manner of columns and rows are vertical and horizontal. In a table, there
are some specific numbers of columns which remains present and is generally
known as fields. There is no strict upper limit on the overall number of records which
are defined by rows in the table.
Q4) Compare SQL with Oracle?
Ans:
SQL Oracle
It is more scalable and secure than Oracle Oracle too is secure and scalable but not up to the extent SQL
Q5) How the Inner Join in SQL is different from that of Outer Join?
Ans: An Inner join is the one that is useful for the purpose of returning the rows
provided at least two tables are met critically. On the other hand, the outer join is the
one that is useful for returning the value of rows and tables that generally include the
records that must be same in all the tables.
Q6) Can you tell something about the Primary key in SQL and what is its
significance?
Ans: It is basically an array or a group of fields that generally specify a row. It is
considered as one of the unique keys that always have some defined or specific
value. Generally, the users need not worry about anything when it is enabled as it
cannot have a null value.
It is capable to identify all the records in a database simply and the users are free to
get the best possible outcome with minimum efforts. This is exactly what that makes
sure of uniqueness.
Q7) What do you know about database testing and how it can help to get useful
results for the database users?
Ans: It is basically nothing but the back end testing or data testing. It generally
involves keeping an eye on the integrity of the data an organization use. It generally
validates some of the very useful tasks such as database, indexes, columns, tables
as well as triggers. IT also make sure that no duplicate data exist in the database
which causes a very large number of problems and the best part is the junk records
can also be trashed in a very reliable manner. The updating of the record is also a
task that can be made easy with the help of this approach.
Q8) Tell something you know about the SQL constraints?
Ans: These are some important rules in the SQL which are responsible for the
restrictions when it comes to deleting, updating or changing the primary data present
in the database.
Q9) In SQL, what do you know about the composite primary key?
Ans: The key which is created on multiple columns in a table is generally considered
as the Composite primary key. However, it is not always necessary that all of them
have the same meaning.
Q10) Difference Between Stored Procedure & Functions?
Ans:
Stored Procedure Functions
It is a set of pre-compiled SQL Statements which will It will take input from the user and return only o
get executed when we call it value of any data type
Stored Procedure will have an execution plan The function will not have an execution plan
It is may or may not have an input parameter The function must have at least one input paramete
It accepts both input and output parameters Doesn’t have output parameters
We call the stored procedure in another stored We can call a function in another function
procedure
We can call function in stored Procedure We can’t call stored procedure in function
Alter
Drop
Rename
Truncate
copy
Insert
16) What do you mean by Term and how it is different from that of Index?
Ans: When it comes to handling the queries at a faster rate, the Indexes are
preferred widely in SQL and they simply make sure of quick retrieval of the data and
the concerned information from the table present in the database. It is possible to
create the index on a single column or a group of same.
On the other side, a View is basically nothing but the subset of a table and is used
for the purpose of storing the database in a logical manner. It is actually a virtual
table that has rows as well as the columns which are similar to that of a real table.
However, the views contain data that actually don’t belong to them. The same is
considered when it comes to restricting the access of a database.
Q17) Is it possible for the users to compare the test for the NULL values in
SQL?
Ans: No, the same is not possible
Q18) What do you mean by the term SQL?
Ans: It stands for Structured Query Language and is a powerful language to
communicate the database and monitor the concerned tasks easily and reliably. A lot
of important tasks such as updating the database, controlling, modifications, as well
as deletion of data, can be performed with this task.
It comes with so many dedicated features in it that are good enough to make a
database completely useful and reliable to consider. There are many commands that
can be considered and help to save a lot of time when it comes to getting the best
out of a database.
Q19) Tell something about Subquery in the SQL?
Ans: It is basically a SQL query and is generally regarded as the subset of the select
statement and the process of those tasks that generally make sure of filtering the
conditions related to the main query.
Q20) In a query, is it possible for the users to avoid the duplicate records? How
this can be done?
Ans: Yes, the same is possible and there are many methods that can help users to
get the favorable fortune in this matter. The best one is to deploy the SQL SELECT
DISTINCT query which issued to return the unique values. All the repeated values or
the ones which are duplicate get deleted automatically.
Q21) What is the significance of the default constraint in SQL?
Ans: It is used when it comes to including a default value in a column in case there
is no new value provided at the time a record is inserted.
Q22) What are the factors that can affect the functionality of a database
according to you?
Ans: There are certain things that largely matters. The first and the foremost is
nothing but the size of the database in terms of its storing capacity. Of course, for a
bigger database, the needs are complex and so does its management.
Thus, the first thing that can help to keep up the pace in this matter is a powerful
query language or a controlling procedure. Next thing is the security of the database.
In addition to this, the experience of the experts handling the important operations
can also largely impact the database. Moreover, there are conditions on the
operation of the same that also largely matter.
Q23) How can you put separate the Rename and the Alias?
Ans: A permanent name which is given to a table or a column in SQL is considered
as “Rename” whereas the temporary name
given to the same is considered as “Alias”
Q24) What is a Join and what are the different types of the same present in the
SQL?
Ans: Join is basically a query that is useful for the purpose of retrieving the columns
and the rows. It is useful when users have to handle a very large number of tables at
the same time. The different types of Joins that are present in the SQL are Right Jin,
Inner Join, Left Join, Outer Join, and Upper Join.
Q25) What do you know about the NULL value in the SQL?
Ans: It is basically a field which doesn’t have any value in SQL. It is totally different
from that of a zero value and must not be put equal or confused with the same.
These fields are left blank during the creation of the records.
Q26) How can you say Normalization is a useful process in database
management?
Ans: It is basically an approach with one of its primary aims is to simply impose a
strict upper limit on the redundancy of the data. The users are free to go ahead with
many of the normalizations forms present in the SQL and a few of them are First,
second, third and Boyce Normal Form.
Q27) What do you know about the stored procedure?
Ans: It is nothing but an array of some important SQL statements that are stored in
the database and are responsible for performing a specific task.
Q28) Name the SQL procedure which makes sure an immediate action in
response to an event?
Ans: The same is Trigger
Q29) In the Boolean Data Field, what are the possible values that users can
simply store?
Ans: This can be TRUE or FALSE
Q30) Name the types of Indexes of which are available in SQL
Ans: There are three important types of Indexes and they are
Unique Index
Clustered Index
Non-Clustered Index.
Q31) In SQL, what is the best thing about the Views you have come across?
Ans: These are several good things about them. The very first thing is they consume
almost no space which makes them good enough to be considered in every
situation. At the same time, the users are able to consider views for simply retrieving
the outcomes that belong to queries which are complicated in nature.
The same may need to be executed frequently. It is possible to consider this when it
comes to restricting access to the database.
Q32) What is SQL?
Ans: SQL- A Structured Query Language, It is also pronounced as “SEQUEL” and it
a Non-procedural Language which is used to operate all relational database. Used
for Database communication. Its a standard language that can be used to perform
the tasks like data retrieval, data update, insert or delete data from a database.
Features of SQL:
Portability
Client-server architecture,
Interactive,
High level,
SQL Vs MySQL
SQL MYSQL
SQL stands for Structured Query MySQL is an RDMS (Relational Database Management
Language System)
Allow for accessing and manipulating MySQL is a database management system, like SQL
DB's Server, Oracle, Postgres, Informix, etc
Basically works as the prompter to a It Facilitates multi-user access to a huge number of DBs
DBMS
SQL codes & commands are used in MySQL has SQL at its core and requires future upgrades
various DBMS and RDBMS systems mostly
such as MySQL.
UPDATE Statement
DELETE Statement
ALTER Statement
DROP Statement
RENAME Statement
TRUNCATE Statement
REVOKE Statement
ROLLBACK Statement
SAVEPOINT Statement
Q36) What are various DDL commands in SQL? Give a brief description of
their purposes.
Ans: DDL Commands are used to define the structure of the table
Subscribe to our youtube channel to get new updates..!
1. CREATE
It is used to create database objects like tables, views, synonyms, indexes.
Creating Table:
Syntax-
1 Create table table_name(columname1 datatype(size), columname2 datatype(size),....);
2. ALTER
It is used to change the existing table structure.
Alter a) add
b) modify
c)drop
a) Add:
It is used to add columns into an existing table
Syntax:
1 Alter table table_name add(columnname1 datatype(size), columname2 datatype(size),...
b) Modify:
It is used to change column Datatype or datatype size only.
Syntax:
1 Alter table table_name modify(columnname1 datatype(size), columnname2 datatype(size)
c) Drop:
It is used to drop columns from the table.
Method1:
If we want to drop a single column at a time without using parentheses then we are
using the following syntax.
Syntax:
1 alter table table_namedrop column col_name1; -- drop ONE column
Method2:
If we want to drop single or multiple columns at a time with using paranthesis then
we are using the following syntax.
Syntax:
1 alter table table_name drop(column_name_list);
Note:
In all databases, we can’t drop all columns in the table.
3. DROP
It is used to remove database objects from the database.
Syntax:
1 Drop object object_name;
2 (or)
Drop table table_name;
3
(or)
4 Drop view view_name;
5
4. RENAME
It is used to renaming a table.
Syntax:
1 Rename old table_name to new table_name;
Renaming a column:
Syntax:
1 Alter table table_name rename column old column_name to new column_name;
5. TRUNCATE
Oracle 7.0 introduced truncate table command it is used to delete all rows
permanently from the table.
Syntax:
1 truncate table table_name;
Q37) What are various DML commands in SQL? Give a brief description of
their purposes.
Ans: DML Commands are used to manipulate data within a table.
There are:: INSERT, UPDATE, DELETE
1. INSERT − It is used to insert data into the table
Method1:
Syntax:
1 Insert into table_name values(values1, value2, value3,……);
Method2:- Using Substitutional operator (&)
Syntax:
1 Insert into table_name values(& columnname1, columnname2,.....);
Method3:- Skipping columns
Syntax:
1 Insert into table_name(col1, col2,...) values(val1, val2, val3,...);
2. UPDATE - It is used to change data in a table.
Syntax:
1 Update table_name set columnname=new value where columnname=old value;
Note: In all databases, we can also use the update statement for inserting data into
a particular shell.
3. DELETE - It is used to delete rows or particular rows from a table.
Syntax:
1 Delete from table_name;
(or)
1 Delete from tablename where condition;
Q38) Difference Between Delete & Truncate?
Ans:
SQL Delete Vs SQL Truncate
DELETE TRUNCATE
It is used to delete all the records row by row It is used to delete all the records at a time
By using delete command we can delete a By using truncate we cannot delete specific record
specific record
Where condition we can use with the delete Where condition will not work with truncate
command
Delete will work slow compare with truncate Truncate will work fast compare with delete
Delete will not reset auto-generate id. Once Truncate will reset auto-generate id from starting number
when we delete all the records from the table.
The Current SQL Statement Replaces the Previous SQL Statement in the Buffer.
The SQL Statement Can be Divided Into Different Lines Within The SQL Buffer.
Only One Line i.e., The Current Line Can be Active at a Time in the SQL Buffer.
At SQL Prompt, Editing is Possible Only in The Current SQL Buffer Line.
To Run the Previous OR Current SQL Statement in the Buffer Type “/” at SQL Prompt.
The Return Value Has The Same Data Type as Argument CHAR Type (CHAR or VARCHAR2)
UPPER Function:
It Converts the Alpha Character Values to Upper Case.
Words are Delimited by White Space or Characters That are Not Alphanumeric
LPAD Function:
Pads The Character Value Right Justified to a Total Width of ‘n’ Character Positions.
RPAD Function:
Pads the Character Value Left Justified to a Total Width of ‘n’ Character positions.
LTRIM Function:
It Enables to TRIM Heading Character From a Character String.
All The Leftmost Character That Appear in The SET are Removed.
RTRIM Function:
It Enables the Trimming of Trailing Character From a Character STRING.
All the Right Most Characters That Appear in The Set are Removed.
TRIM Function:
It Enables to TRIM Heading or Trailing Character or Both From a Character String.
If LEADING is Specified Concentrates On Leading Characters.
If TRAILING is Specified Concentrates on Trailing Characters.
If BOTH OR None is Specified Concentrates Both on LEADING and TRAILING.
Return the VARCHAR2 Type.
Advanced SQL Interview Questions & Answers
Q41) How to Open SQL Server?
Ans:
Goto -> Start -> All Programms -> Microsoft SQL Server 2008 R2 -> SQL Server managem
1 Studio.
Q42) What are SQL Injections? And How to Prevent SQL Injection Attacks?
Ans: It is a mechanism of getting secure data from the database.
SQL Injection Attacks::
By providing proper validations for input fields.
It will process on a single row at a time & return It will process on multiple rows at a time & retu
only one value of any database multiple rows (or) single row from the table
The return type of scalar-valued function is a The return type of table-valued function is a table
datatype
The scalar-valued function will have as begin The table-valued function will not have as begin end
block end
Syntax to call Scalar Valued Functions is:: Syntax to call Table-Valued Functions is::
1 SELECT dbo. funname(values); 1 SELECT * FROM dbo.funname(values);
Q44) How can you say that Database testing is different from that of GUI
testing?
Ans:
GUI testing is always performed at the front end whereas the Database testing is performed at
the back end
When it comes to dealing with the testable items, generally the users prefer GUI testing. These
items are present clearly./ On the other hand, the Database testing deals with the testable items
that are hidden and are not directly visible to the users
Structured Query Language largely matters in Database approach where the same doesn’t have
any application with the GUI
Invalidating the test boxes are a part of GUI database whereas the Database testing is totally
different in this manner
Q45) Write a Query to view the indexes that are applied on the table?
Ans:
1 stored procedure_helpindex table_name
Q46) Difference Between Long & Lob Datatypes?
Ans:
Long Lob
A table can contain only one long column A table can contain more than Lob column
A subquery cannot select a Long data type column A subquery can select Lob Column
NVL Function internally uses implicit conversions i.e NVL Function returns a value if the exp1,
exp2 is not belonged to the same datatype also if exp2 automatically converted into exp1
whereas in coalesce function exp1, exp2 must belong to the same data type.
Examples1::
1 SELECT nvl(‘a’, sysdate) FROM dual;
Output:: a
Examples2::
1 SELECT Coalesce(‘a’, sysdate) FROM dual;
The portion of dimly that involves information retrieval is called a query language.
The view does not store data Materialized view stores data
Security purpose Improved performance purpose
When we ar4e dropping base table then view can’t be When we are dropping base table also materializ
accessible view can be accessible
Transactions Consist of DML Statements That Make Up One Consistent Change To The Data,
A DDL Statement OR A DCL Statement is Automatically Committed And Hence Implicitly Ends A
Transaction.
Q61) GRANT Command?
Ans: Syntax::
1 SQL> GRANT< Privilage Name1>, ,
2 ON
3 TO ;
Q62) REVOKE Command?
Ans: Syntax::
1 SQL> REVOKE< Privilage Name1>, ,
2 ON
3 FROM;
They Help in Integrating The Cursors For Dynamic Management of Records At Run Time.
Its complete name is a structured query language Its complete name is procedural Language / Structur
Query Language
It doesn’t have any facility of branching or looping It has the complete facility of branching or looping
In SQL, only one statement can be sent to Oracle It increases the execution time In PL/SQL, a comple
Engine. block of statements can be sent to Oracle engine at a
time, reducing traffic
In SQL, the use of variables is not possible In PL/SQL, the results of the statements can be store
in variables and can be used further as per the
requirement
It doesn’t have the capacity for a procedural It fully supports procedural language
language
In SQL, there is no facility of error management. In In PL/SQL, the results of the statements can be store
case of an error condition, It is the Oracle Engine in variables and can be used further as per the
that tracks it. requirement
Q66) What is a CURSOR?
Ans: CURSOR is a Handle OR Pointer To The CONTEXT AREA
Q67) What is The CURSOR Usage?
Ans: Using a CURSOR, The PL/SQL program can control the CONTEXT AREA, As the
SQL Statement is being processed.
Q68) What are the CURSOR Features?
Ans:
CURSOR Allows to FETCH and process Rows returned by a SELECT statement, One Row at a
time.
A CURSOR is named, such that it can be referenced by the PL/SQL programmer dynamically at
run time.
Q69) What are the Different Types of Constraints?
28
DEC
Saturday
6:30 AM IST
02
JAN
Thursday
6:30 AM IST
11
JAN
Saturday
7:00 AM IST
18
JAN
Saturday
6:30 AM IST
More Batches
Ans:
Null Constraint
Default Constraint
Check Constraint
Q70) %Found
Ans:
This attribute returns boolean value either true or false.
This attribute returns true when the fetch statement returns at least one records.
Syntax:
1
2 cursorname%found
3 SQL>declare
4 Cursor c1 is select * from emp
5 Where ename =’&ename’;
i emp% rowtype;
6 begin
7 open c1;
8 fetch c1 into i;
9 If c1%found then
10 dbms_outpit.put_line(your employee exists’||’ ‘||i.ename|| ‘ ‘||i.sal);
else if c1%not found then
11 dbms_output.put_line(‘your employee does not exists’);
12 end if;
13 close c1;
14 end;
/
15
16
%found
True If fetch statement return at least one row
------------- -------------------------------------------------
False If the fetch statement doesn't return any row
%notfound
True If the fetch statement doesn't return any row
------------ --------------------------------------------------
False If fetch statement return at least one row
%isopen
True If the cursor is already opened
---------- --------------------------------------------------
False If the cursor is not opened
Whenever we are calling autonomous procedure in main transaction and also main transaction
TCL commands never affected on autonomous TCL commands procedure because these are
independence procedure.
If we want to procedure autonomous then we are using autonomous transaction pragma, commit
i.e in declare section of the procedure we are defining autonomous transaction pragma and also
we must use commit in procedure coding.
Bad file
Discard file
Q76) SQL%bulk_rowcount
Ans: Oracle introduced sql%bulk_rowcount the attribute which is used to count the
affected number of rows within each group in bulk bind process. (all statements).
Syntax:
1 sql%bulk_rowcount(index varname);
Q77) Authid current_user
Ans:
When a procedure has an authed current_user clause then those procedures are allowed to
execute the only owner of the procedure.
These procedures are not allowed to executes by another user if any user givings permission
also. Generally whenever we are reading data from the table and performs some DML operations
then only data security principles of view developers use this clause in procedures.
Syntax:
1 Create or replace procedure procedurename(formal parameters)
2 Authid current_user
is/as
3 -----------
4 Begin
5 ----------
6 [exeception]
7
------------
8 End[procedurename];
9
Q78) What is Row-Level-Attribute?
Ans: In this method, a single variable can represent all different datatype into a
single unit. This variable is also called a record type variable.
Ro Level Attribute is represented by using %rowtype.
Syntax:
1 variable_name table_name%rowtype;
Q79) What are the types of Blocks in PL/SQL?
Ans: PL/SQL has 2 types of blocks
Anonymous Block
Named Block
This block does not have a name This block having a name
These blocks are not stored in oracle database These blocks are automatically permanently sto
in Database
These blocks are not allowed to call in the client These blocks are allowed to call in the cli
application application
Q80) Write a PL/SQL cursor program which is used to display total salary from
emp table without using sum() function by using cursor for loop?
Ans:
sql>
1
2 declare
cursor c1 is select*from emp
3 n number(10):=0;
4 begin
5 for i in c1
6 loop
7 n:=n+i.sal;
end loop;
8 dbms_output.put_line (‘total salary is: ‘||’ ‘||n);
9 end;
10 /?
11
Output: total salary is: 42075
Q81) What is Normalization?
Ans: Normalization is a scientific process which is called to decomposing a table into
a number of tables. This process automatically reduces duplicate data and also
automatically avoids insertion, update, deletion problems.
In the design phase of SDLC, database designers design the LOGICAL MODEL of
the database in this logical model only database designers use normalization
process by using normal forms.
Q82) What is Super Key?
Ans: A column or a combination of columns which uniquely identify a record in a
table is called a Super Key.
Q83) What is Candidate Key?
Ans: A minimal super key uniquely identifying a record a table is called candidate
key
(or)
A super key which is a subset of another super key then those super keys are not a
candidate key.
Q84) What is Bad File?
Ans: This file extension is .bad
Bad file stores rejected records based on
1. Data type mismatch
The bad file is automatically created as the same name as Flat file, we can also
create Bad file explicitly by using bad file clause within the control file.
Q85) What is Discard File?
Ans:
1. This file extension is .dsc
2. Discards file we must specify within control file by using the discard file clause.
3. Discard file also stores rejected record based on when clause condition within the control file.
This condition must be satisfied into a table table_name clause.
Q86) What is Autoincrement?
Ans: In all databases generating primary key value automatically is called auto-
increment concept. In Oracle, we are implementing the auto-increment concept by
using row-level triggers, sequences. i.e here we creating sequence in SQL and use
this sequence in PL/SQL row-level trigger.
1 SQL> create table test (sno number(10), primary key, name varchar2(10));
Q87) What is Dynamic SQL?
Ans: It is the combination of SQL, PL/SQL i.e SQL statements are executed
dynamically with PL/SQL block using execute immediate clause.
Generally, in PL/SQL block we are not allowed to use DDL, DCL statements using
Dynamic SQL DDL, DCL statement within PL/SQL block.
Syntax:
1 begin
2 execute immediate ‘sql statement’
3 end;
4 /
Q88) What are the Different SQL Servers Versions available in the market?
Ans:
SQL Servers Versions
Q89) Write a dynamic SQL program to display a number of records from emp
table?
Ans:
SQL>
1
declare
2 z number(10);
3 begin
4 execute immediate ‘select count * FROM emp’
5 into z;
dbms_output.put_line(z);
6 end;
7 /?
8
Q90. Write a dynamic SQL program for passing department number 20 retrieve
dept names, Loc from dept table?
Ans:
SQL>
1 declare
2 v_deptno number(10):=20;
3 v_dname varchar2(10);
4 v_loc varchar2(10);
begin
5 execute immediate ‘select dname, loc FROM dept where deptno=1’ into v_dname
6 v_deptno;
7 dbms_output.put_line(v_dname ||’ ‘|| v_loc);
8 end;
/?
9