oracle sql plsql interview questions

Oracle Sql Plsql Interview Questions and Answers

Q.What are the components of physical database structure of Oracle database?

Answer: Oracle database is comprised of three types of files. One or more datafiles, two are more redo log files, and one or more control files.

Q.What are the components of logical database structure of Oracle database?

Answer: There are tablespaces and database’s schema objects.

Q.What is a tablespace?

Answer: A database is divided into Logical Storage Unit called tablespaces. A tablespace is used to grouped related logical structures together.

Q.What is SYSTEM tablespace and when is it created?

Answer: Every Oracle database contains a tablespace named SYSTEM, which is automatically created when the database is created. The SYSTEM tablespace always contains the data dictionary tables for the entire database.

Q.Explain the relationship among database, tablespace and data file.

Answer: Each databases logically divided into one or more tablespaces one or more data files are explicitly created for each tablespace.

Q.What is schema?

Answer: A schema is collection of database objects of a user.

Q.What are Schema Objects?

Schema objects are the logical structures that directly refer to the database’s data. Schema objects include tables, views, sequences, synonyms, indexes, clusters, database triggers, procedures, functions packages and database links.

Q.Can objects of the same schema reside in different tablespaces?

Yes.

Q.Can a tablespace hold objects from different schemes?

Yes.

Q.What is Oracle table?

Answer: A table is the basic unit of data storage in an Oracle database. The tables of a database hold all of the user accessible data. Table data is stored in rows and columns.

Q.What is an Oracle view?

Answer: A view is a virtual table. Every view has a query attached to it. (The query is a SELECT statement that identifies the columns and rows of the table(s) the view uses.)

Q.What is Partial Backup ?

Answer: A Partial Backup is any operating system backup short of a full backup, taken while the database is open or shut down.

Q.What is Mirrored on-line Redo Log ?

Answer: A mirrored on-line redo log consists of copies of on-line redo log files physically located on separate disks, changes made to one member of the group are made to all members.

Q.What is Full Backup ?

Answer: A full backup is an operating system backup of all data files, on-line redo log files and control file that constitute ORACLE database and the parameter.

Q.Can a View based on another View ?

Answer: Yes.

Q.Can a Tablespace hold objects from different Schemes ?

Answer: Yes.

Q.Can objects of the same Schema reside in different tablespaces.?

Answer: Yes.

Q.What is the use of Control File ?

Answer:  When an instance of an ORACLE database is started, its control file is used to identify the database and redo log files that must be opened for database operation to proceed. It is also used in database recovery.

Q.Do View contain Data ?

Answer: Views do not contain or store data.

Q.What are the Referential actions supported by FOREIGN KEY integrity constraint ?

UPDATE and DELETE Restrict – A referential integrity rule that disallows the update or deletion of referenced data. DELETE Cascade – When a referenced row is deleted all associated dependent rows are deleted.

Q.What are the type of Synonyms?

Answer: There are two types of Synonyms Private and Public.

Q.What is a Redo Log ?

Answer: The set of Redo Log files YSDATE,UID,USER or USERENV SQL functions, or the pseudo columns LEVEL or ROWNUM.

Q.What is an Index Segment ?

Answer: Each Index has an Index segment that stores all of its data.

Q.Explain the relationship among Database, Tablespace and Data file.?

Answer: Each databases logically divided into one or more tablespaces one or more data files are explicitly created for each tablespace

Q.What are the different type of Segments ?

Answer: Data Segment, Index Segment, Rollback Segment and Temporary Segment.

Q.What are Clusters ?

Answer: Clusters are groups of one or more tables physically stores together to share common columns and are often used together.

Q.What is an Integrity Constrains ?

Answer: An integrity constraint is a declarative way to define a business rule for a column of a table.

Q.What is an Index ?

Answer: An Index is an optional structure associated with a table to have direct access to rows, which can be created to increase the performance of data retrieval. Index can be created on one or more columns of a table.

Q.What is an Extent ?

Answer: An Extent is a specific number of contiguous data blocks, obtained in a single allocation, and used to store a specific type of information.

Q.What is a View ?

Answer: A view is a virtual table. Every view has a Query attached to it. (The Query is a SELECT statement that identifies the columns and rows of the table(s) the view uses.)

Q.What is Table ?

Answer: A table is the basic unit of data storage in an ORACLE database. The tables of a database hold all of the user accessible data. Table data is stored in rows and columns.

Q.Can a view based on another view?

Answer: Yes.

Q.What are the advantages of views?

Answer: – Provide an additional level of table security, by restricting access to a predetermined set of rows and columns of a table.
– Hide data complexity.
– Simplify commands for the user.
– Present the data in a different perspective from that of the base table.
– Store complex queries.

Q.What is an Oracle sequence?

Answer: A sequence generates a serial list of unique numbers for numerical columns of a database’s tables.

Q.What is a synonym?

Answer: A synonym is an alias for a table, view, sequence or program unit.

Q.What are the types of synonyms?

Answer: There are two types of synonyms private and public.

Q.What is a private synonym?

Answer: Only its owner can access a private synonym.

Q.What is a public synonym?

Answer: Any database user can access a public synonym.

Q.What are synonyms used for?

Answer: – Mask the real name and owner of an object.
– Provide public access to an object
– Provide location transparency for tables, views or program units of a remote database.
– Simplify the SQL statements for database users.

Q.What is an Oracle index?

Answer: An index is an optional structure associated with a table to have direct access to rows, which can be created to increase the performance of data retrieval. Index can be created on one or more columns of a table.

Q.How are the index updates?

Answer: Indexes are automatically maintained and used by Oracle. Changes to table data are automatically incorporated into all relevant indexes.

Q.What is a Tablespace?

Answer: A database is divided into Logical Storage Unit called tablespaces. A tablespace is used to grouped related logical structures together

Q.What is Rollback Segment ?

Answer: A Database contains one or more Rollback Segments to temporarily store “undo” information.

Q.What are the Characteristics of Data Files ?

Answer: A data file can be associated with only one database. Once created a data file can’t change size. One or more data files form a logical unit of database storage called a tablespace.

Q.How to define Data Block size ?

Answer: A data block size is specified for each ORACLE database when the database is created. A database users and allocated free database space in ORACLE datablocks. Block size is specified in INIT.ORA file and can’t be changed latter.

Q.What does a Control file Contain ?

Answer: A Control file records the physical structure of the database. It contains the following information.
Database Name
Names and locations of a database’s files and redolog files.
Time stamp of database creation.

Q.What is difference between UNIQUE constraint and PRIMARY KEY constraint ?

Answer: A column defined as UNIQUE can contain Nulls while a column defined as PRIMARY KEY can’t contain Nulls.

Q.What is Index Cluster ?

Answer: A Cluster with an index on the Cluster Key

Q.When does a Transaction end ?

Answer: When it is committed or Rollbacked.

Q.What is the effect of setting the value “ALL_ROWS” for OPTIMIZER_GOAL parameter of the ALTER SESSION command ? What are the factors that affect OPTIMIZER in choosing an Optimization approach ?

Answer:  Answer The OPTIMIZER_MODE initialization parameter Statistics in the Data Dictionary the OPTIMIZER_GOAL parameter of the ALTER SESSION command hints in the statement.

Q.What is the effect of setting the value “CHOOSE” for OPTIMIZER_GOAL, parameter of the ALTER SESSION Command ?

Answer: The Optimizer chooses Cost_based approach and optimizes with the goal of best throughput if statistics for atleast one of the tables accessed by the SQL statement exist in the data dictionary. Otherwise the OPTIMIZER chooses RULE_based approach.

Q.How does one create a new database? (for DBA)

Answer: One can create and modify Oracle databases using the Oracle “dbca” (Database Configuration Assistant) utility. The dbca utility is located in the $ORACLE_HOME/bin directory. The Oracle Universal Installer (oui) normally starts it after installing the database server software.
One can also create databases manually using scripts. This option, however, is falling out of fashion, as it is quite involved and error prone. Look at this example for creating and Oracle 9i database:
CONNECT SYS AS SYSDBA
ALTER SYSTEM SET DB_CREATE_FILE_DEST=’/u01/oradata/’;
ALTER SYSTEM SET DB_CREATE_ONLINE_LOG_DEST_1=’/u02/oradata/’;
ALTER SYSTEM SET DB_CREATE_ONLINE_LOG_DEST_2=’/u03/oradata/’;
CREATE DATABASE;

Q.what database block size should I use? (for DBA)

Answer: Oracle recommends that your database block size match, or be multiples of your operating system block size. One can use smaller block sizes, but the performance cost is significant. Your choice should depend on the type of application you are running. If you have many small transactions as with OLTP, use a smaller block size. With fewer but larger transactions, as with a DSS application, use a larger block size. If you are using a volume manager, consider your “operating system block size” to be 8K. This is because volume manager products use 8K blocks (and this is not configurable).

Q.What are the different approaches used by Optimizer in choosing an execution plan ?

Answer: Rule-based and Cost-based.

Q.What does ROLLBACK do ?

Answer: ROLLBACK retracts any of the changes resulting from the SQL statements in the transaction.

Q.What is difference between varchar and varchar2?

Answer:  Varchar means fixed length char              varchar2 means variable length char

Q.What is Pro*C? What is OCI?

Answer: Pro *C

The Pro* c/C++ precompiler takes the SQL statement that embedded in C/C++ code convert into standard C/C++ code. When successfully precompile this code, the result is a C or C++ program that we compile and used to build the application that access the Oracle Application.

OCI: – OCI refer to Oracle Call interface is set of Low Level API (Application Program Interface Call) used to interact with Oracle Database. By OCI one can use the operation such as Logon, Fatch, parse, execute etc. Generally these are written in C/C++.

Q.What is the difference between “NULL in C” and “NULL in Oracle?

Answer:  The NULL in C treated as Zero or void. but in SQL NULL value is Non or blank represented it can’t manipulated

Q.In Oracle varchar2 takes dynamic space for storage then why char is still in oracle?

Answer:  The major difference between varchar2 and char is fixed length and variable length. Varchar2 have variable length mean if we declare as 20 space and its use only 5 space the memory assign only 5. But in char takes daclare space while use any number space less than declare

Q.what are the difference between and constraints and triggers?

Answer:  Constraints are used to maintain the integrity and atomicity of database .in other words it can be said they are used to prevent invalid data entry. The main 5 constraints are

NOT NULL, PRIMARY KEY, FOREIGN KEY, UNIQUE KEY and CHECK

Triggers are basically stored procedures, which automatically fired when any insert, update or delete is issued on table

Another most imp. Diff. is that trigger effected only those row after which trigger applied but constraint effected all row of table.

Q.what is normalization? What is the advantage of normalization (briefly)

Answer:  1.The process of separating data into distinct, unique sets is called normalization. This is implemented to improve the performance of the RDBMS, such as reduces redundancy of data and data inconsistency.

2.Normalization is the process of removing redundant data from your tables in order to improve storage efficiency, data integrity and scalability.

3.Database normalization is a series of steps followed to obtain a database design that allows for consistent storage and efficient access of data in a relational database. These steps reduce data redundancy and the risk of data becoming inconsistent.

4.Normalization is the process used to reduce the unnecessary repetition of data i.e., redundant data. It is performed on the data, which is redundant and makes the data in a normalized format. It is of step-by-step process IstNotmal, FormIIndNormal, formIIIrdNormal, formIVthNormal form or Boyce odd Normal form By performing this we will get the data in the Normalized formati.,e from DBMS to RDBMS.

Q.How the logs are escalated?

Answer:  There are different types are logs which are logged by Oracle Database Engine. A DBA has to look in for alter log which exist background dump dust. The seviourity of the problem are analysed and escalated based on the information provided by the alter log.

Q.What is structure of Database?

Answer:  1.Oracle database usually contains one database and a single instance. But, Oracle 9i, 10g RAC (Real Application Clusters) can have multiple instances to interact with a single database for high availability.

Instance is non-persistent, memory based background processes and structures.

Database is persistent, disk based, data and control files

2.Physical Structure of Database:

One or more data files, control file(s), Redo log file(s) and init.ora file

Logical Structure of Database:

Table spaces, segments, extents, blocks

Q.what is the difference between primary key, unique key, and surrogate key? 

Answer:  Primary Key: A column in a table whose values uniquely identify the rows in the table. A primary key value cannot be NULL.

Unique Key: Unique Keys are used to uniquely identify each row in an Oracle table. There can be one and only one row for each unique key value.

Surrogate Key: A system generated key with no business value. Usually implemented with database-generated sequences.

Primary Key                                                     Unique key

1.There is only one                                         1.  There may be more than 1

Primary key for I table                          Unique Key in table

2.It can contain Null Value                    2.  It can contain Null Value

Q.what are the diffrent file types that are supported by SQL*Loader?

Answer:  a.direct method (skips dbcache, no redo generation)

  1. conventional method (just opposite of direct load)

Q.How to find how many database reside in Oracle server in query?

Answer:  select count(*) from v$database;

Q.What spfile/init.ora file parameter exists to force the CBO to make the execution path of a given statement use an index, even if the index scan may appear to be calculated as more costly?

Answer:  CBO (Cost Based Optimizer): Generates an execution plan for a SQL statement Optimizer_index_cost_adj parameter can be set to help CBO to decide an execution plan, which affects the speed of SQL query. We can also make necessary changes to the following parameters to effect CBO performance:

Optimizer_search_limit & optimizer_max_permutations

Q.How many memory layers are in the shared pool?

Answer:  The shared pool portion of the SGA contains three major areas: library cache, dictionary cache, buffers for parallel execution messages, and control structures.

Q.What are the attributes of the Virtual Indexes?

These are permanent and continue to exist unless we drop them.

Their creation will not affect existing and new sessions. Only sessions marked for Virtual Index usage will become aware of their existence.

Such indexes will be used only when the hidden parameter “_use_nosegment_indexes” is set to true.

The Rule based optimizer did not recognize Virtual Indexes when I

Tested, however, CBO recognizes them. In all of my examples, I have used CBO. However, I did not carry out intensive testing in RBO and you may come across exceptions to this view.

Dictionary view DBA_SEGMENTS will not show an entry for Virtual Indexes. The table DBA_INDEXES and DBA_OBJECTS will have an entry for them in Oracle 8i; in Oracle 9i onwards, DBA_INDEXES no longer show Virtual Indexes.

Virtual Indexes cannot be altered and throw a “fake index” error!

Virtual Indexes can be analyzed, using the ANALYZE command or DBMS_STATS package, but the statistics cannot be viewed (in Oracle 8i, DBA_INDEXES will not show this either). Oracle may be generating artificial statistics and storing it somewhere for referring it later.

Creating Virtual Index

Creating a Virtual Index can be achieved by using the NOSEGMENT   clause with the CREATE INDEX command.

Q.What is meant by Virtual Indexes in Oracle?

Answer:  Virtual Indexes are another undocumented feature used by Oracle. Virtual indexes, as the name suggests are pseudo-indexes that will not behave the same way that normal indexes behave, and are meant for a very specific purpose. A virtual index is created in a slightly different manner than the normal indexes. A virtual index has no segment pegged to it, i.e., the DBA_SEGMENTS view will not show an entry for this.

Oracle handles such indexes internally and few required dictionary tables are updated so that the optimizer can be made aware of its presence and generate an execution plan considering such indexes. As per Oracle, this functionality is not intended for standalone usage. It is part of the Oracle Enterprise Manger Tuning Pack (Virtual Index Wizard).

The virtual index wizard functionality allows the user to test a potential new index prior to actually building the new index in the database.It allows the CBO to evaluate the potential new index for a selected SQL statement by building an explain plan that is aware of the potential new index.

This allows the user to determine if the optimizer would use the index, once implemented.

Oracle Sql Plsql Interview Questions           Oracle Sql Plsql Interview Questions and Answers

Q.What are materialized views? When are they used?

Answer:  Materialized view is like a view but stores both definition of a view plus the rows resulting from execution of the view. It uses a query as the bases and the query is executated at the time the view is created and the results are stored in a table. You can define the Materialized view with the same storage parametes as any other table and place it in any tablespace of your choice. You can also index and partition the Materialized view table like other tables to improve performance of queries executed aginst them.

Use of Meterialized view:-

Expensive operations such as joins and aggregations do not need to be re executed.

If the query is astisfied with data in a Meterialized view, the server transforms the query to reference the view rather than the base tables.

Q.What is a functional index – explain?

Function-based indexes can use any Function or Object method that is declared as repeatable.

Queries using expressions can use the index.

Ex: – CREATE INDEX sales_margin_inx ON sales (revenue – cost);

Sql> SELECT ordid

FROM sales

WHERE (revenue – cost) > 1000;

We have to enable Function-based indexes by enableing the following initialization parameters

ALTER SESSION SET QUERY_REWRITE_ENABLED = TRUE;

ALTER SESSION SET QUERY_REWRITE_INTEGRITY = TRUSTED;

Q.Where we use bitmap index?

Answer:  a. Bitmap indexes are most appropriate for columns having low distinct values.

  1. We can use bitmap index where cardinality is very low like gender column or color column.

Q.What is an extent?

Answer:  a. An extent is the smallest unit of storage allocation comprising collection of Blocks.

  1. Well an extent is a chunk of a space that is used by database segments when a segment is created it allocates extents.

Q.How to you move from dedicated server Process to a Shared Server Process

Answer:  Use DBCA (DATABASE CONFIGUARATION ASSISTANT) toolYou will get the option to select shared server mode.

Q.What are the components of physical database structure of Oracle database?

  1. Totally there are 6 files (components) of physical database structure.3 mandatory & 3 optional. Three mandatory files are

1> data file: store actual data

2> control file: stores structural & status information of database.

3> redo log file: stores changed/committed data

Three optional files are

4>-parameter file: stores all size related parameters note: this file is mandatory for a1st time u create a database, and then it is optional.

5> archive log file: its offline copy of redo log files

6>-password file: used to make normal user to behave as a super user.

  1. Control files
  2. Init file
  3. Log files 4. Redo/archive log files
  4. data files
  5. Physical components of oracle database are control files, redo log files and datafiles.

Control file: control file is read in the mount state of database. Control file is a   small binary file, which records the physical structure of database, which includes Database name

Names and locations of datafiles and online redo log files. Timestamp of database creation Checkpoint information   current logs sequence number.

Redo log files: This files saves all the changes that are made to the database as they occur. This plays a great role in the database recovery.

Datafiles: datafiles are the physical files, which stores data of all logical   structure.

Q.What are the components of logical database structure of Oracle database

Answer:  Tablespace, segments, extents, data Blocks.

A logical unit of storage of database is called Tablespace.

A segment is a space allocated for a specific logical storage structure within a tablespace.

Extents: Space allocated to a segments.

Datablocks: Oracle server manage the storage space in the datafiles in units is called data blocks or oracle blocks.

Q.What are the different types of segments?

Answer:  table segment, index segment, IOT, cluster, temp segment, data segment.

Q.Can you name few DBMS packages and their use?

Answer:

DBMS_OUTPUT.PUT_LINE (‘strings’);

Print out the strings

DBMS_UTILITY.get_time ()

get the current time

DBMS_ALERT

e.g       begin

dbms_alert.register(‘myregister’);

end

To register interst in a named alert

Q.How can be determine the size of the log files.

Answer:  Select sum (bytes)/1024/1024 size_in_mb from v$log;

Q.How can be determine the size of the database?

Answer: A.  Select sum (bytes)/1024/1024/1024 Size_in_GB from dba_data_files;

  1. Select sum (bytes)/1024/1024 from v_$datafile + select sum (bytes)/1024/1024 from v_$logfile will give u the total size of the database
  2. Select (select sum (bytes/1024/1024/1024) from v$datafile) +( select sum(bytes/1024/1024/1024) from v$tempfile) + (select sum(bytes/1024/1024/1024) from v$log) “Size of Database in GB” from dual.

Q.How can you check which user has which Role.

Answer:  desc dba_tab_privs (OR) Can use ROLE_TAB_PRIVS also (OR) select * from dba_role_privs order by grantee;

Q.Can you start a database without SPfile in oracle 9i?

Answer:  While starting database Oracle reads spfiledb.ora, spfile.ora, initdb.ora or init.ora file. Yes it is possible to start the database using init.ora file only. The main advantage of using the SPFILE.ora is only to make changes to the dynamic initialization parameters without restarting the database using the SCOPE option. The changes will be stored in the spfile only and if you start the database using “pfile” option those changes wont be applicable to the database.

Q.Do a view contain data?

Answer:  A view does not contain any data of its own, but is like a window through which data from other tables can be viewed and changed

The answer depends on the type of view. In case of normal view, the ans is NO it only contains query based on a base table but in case of materialized view, YES it does contain data and for the updated data in the base table, it needs to be refreshed.

NO: Because view is for view one or more tables data like query.

Q.What is Oracle table?

Answer:  A table is the most commonly used form of storing user data.

A table is used to store the information in form of rows &columns in the database.

Table is a segment (type of Segments), which is used to store user data. Tables can have partitions (value wise, date period wise) and each partition can have separate tablespace for better performance. The Collection of informations stored in the structured format that is called a table.

Q.Can objects of the same schema reside in different tablespaces?

Answer:  Yes, it can. For example if you specify a different tablepace (B) for indexes, the indexes of the tables that the user create would be residing in B, and the table would reside in the user’s default tablespace A.

Yes: Schema objects can stored in different tablespace and a tablespace can contained one or more schema objects data.

Q.What is an Oracle index?

Answer:  An Index is a tree structure that allows direct access to a row in a table. Indexes can be classified based on their logical design or on their physical implementation.

The Logical classification groups indexes from an application perspective, while the physical classification is derived from the way the indexes are stored

An index is a schema object that can speed up the retrieval of rows by using pointers. If you do not have an index, then a full table scan occurs. Its purpose is to reduce disk I/O by using an indexed path to locate data quickly. If a table is dropped, the corresponding indexes are also dropped.

It is created in existing table to locate rows more quickly&efficiently. The users cannot see the indexes; they are just used to speed up the queries

Q.Can we create index on long raw column?

Answer:  NO we can’t create index on long raw column.

Q.What is the basic element of base configuration of an Oracle database?

Answer:  It consists of – one or more data files

– One or more control files

– Two or more redo log files

The database contains – Multiple users/schema’s

– One or more rollback segments

– One or more tablespaces

– Data dictionary tables.

User objects (table, indexes, views etc.)

Q.What are clusters?

Answer:  Groups of tables physically stored together because they share common columns and are often used together is called clusters.

Q.What is the function of redo log?

Answer:  The primary function of the redo log is to record all changes made to data.

Q.What are the characteristics of data files?

Answer:  Characterstics of Data File:

– A Data file can be associated with only one database.

– Once created, a data file cannot change is size.

– One or more data files form a logical unit of database storage called a Tablespace.

Datafile size can be change by using ALTER DATABASE …..RESIZE command.

Q.How do you implement one-to-one, one-to-many and many-to-many relationships while designing tables?

Answer: One-to-One relationship can be implemented as a single table and rarely as two tableswith primary and foreign key relationships.
One-to-Many relationships are implemented by splitting the data into two tables with primary key and foreign key relationships.
Many-to-Many relationships are implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table.
It will be a good idea to read up a database designing fundamentals text book.

Q.What’s the difference between a primary key and a unique key?
Answer: Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn’t allow NULLs, but nique key allows one NULL only.
Q.What are user defined datatypes and when you should go for them?
Answer: User defined datatypes let you extend the base SQL Server datatypes by providing a descriptive name, and format to the database. Take for example, in your database, there is a column called Flight_Num which appears in many tables. In all these tables it should be varchar(8). In this case you could create a user defined datatype called Flight_num_type of varchar(8) and use it across all your tables.

Q.What is bit datatype and what’s the information that can be stored inside a bit column?
Answer: Bit datatype is used to store boolean information like 1 or 0 (true or false). Untill SQL Server 6.5 bit datatype could hold either a 1 or 0 and there was no support for NULL. But from SQL Server 7.0 onwards, bit datatype can represent a third state, which is NULL.
Q.Define candidate key, alternate key, composite key
Answer: A candidate key is one that can identify each row of a table uniquely. Generally a candidate key becomes the primary key of the table. If the table has more than one candidate key, one of them will become the primary key, and the rest are called alternate keys.
A key formed by combining at least two or more columns is called composite key.
Q.What are defaults? Is there a column to which a default can’t be bound?
Answer: A default is a value that will be used by a column, if no value is supplied to that column while inserting data. IDENTITY columns and timestamp columns can’t have defaults bound to them. See CREATE DEFUALT in books online.
Q.What is a transaction and what are ACID properties?
Answer: A transaction is a logical unit of work in which, all the steps must be performed or none. ACID stands for Atomicity, Consistency, Isolation, Durability. These are the properties of a transaction. For more information and explanation of these properties, see SQL Server books online or any RDBMS fundamentals text book.

Q.Explain different isolation levels
Answer: An isolation level determines the degree of isolation of data between concurrent transactions. The default SQL Server isolation level is Read Committed. Here are the other isolation levels (in the ascending order of isolation): Read Uncommitted, Read Committed, Repeatable Read, Serializable. See SQL Server books online for an explanation of the isolation levels. Be sure to read about SET TRANSACTION ISOLATION LEVEL, which lets you customize the isolation level at the connection level.

Q.CREATE INDEX myIndex ON myTable(myColumn)
Answer: What type of Index will get created after executing the above statement?
Non-clustered index. Important thing to note: By default a clustered index gets created on the primary key, unless specified otherwise.
Q.What’s the maximum size of a row?
Answer: 8060 bytes. Don’t be surprised with questions like ‘what is the maximum number of columns per table’. Check out SQL Server books online for the page titled: “Maximum Capacity Specifications”.
Q.Explain Active/Active and Active/Passive cluster configurations
Answer: Hopefully you have experience setting up cluster servers. But if you don’t, at least be familiar with the way clustering works and the two clustering configurations Active/Active and Active/Passive. SQL Server books online has enough information on this topic and there is a good white paper available on Microsoft site.
Q.Explain the architecture of SQL Server
Answer: This is a very important question and you better be able to answer it if consider yourself a DBA. SQL Server books online is the best place to read about SQL Server architecture. Read up the chapter dedicated to SQL Server Architecture.
Q.What is lock escalation?
Answer: Lock escalation is the process of converting a lot of low level locks (like row locks, page locks) into higher level locks (like table locks). Every lock is a memory structure too many locks would mean, more memory being occupied by locks. To prevent this from happening, SQL Server escalates the many fine-grain locks to fewer coarse-grain locks. Lock escalation threshold was definable in SQL Server 6.5, but from SQL Server 7.0 onwards it’s dynamically managed by SQL Server.
Q.What’s the difference between DELETE TABLE and TRUNCATE TABLE commands?

Answer: DELETE TABLE is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow. TRUNCATE TABLE also deletes all the rows in a table, but it won’t log the deletion of each row, instead it logs the deallocation of the data pages of the table, which makes it faster. Of course, TRUNCATE TABLE can be rolled back.
Q.Explain the storage models of OLAP
Answer: Check out MOLAP, ROLAP and HOLAP in SQL Server books online for more infomation.
Q.What are the new features introduced in SQL Server 2000 (or the latest release of SQL Server at the time of your interview)? What changed between the previous version of SQL Server and the current version?
Answer: This question is generally asked to see how current is your knowledge. Generally there is a section in the beginning of the books online titled “What’s New”, which has all such information. Of course, reading just that is not enough, you should have tried those things to better answer the questions. Also check out the section titled “Backward Compatibility” in books online which talks about the changes that have taken place in the new version.
Q.What are constraints? Explain different types of constraints
Answer: Constraints enable the RDBMS enforce the integrity of the database automatically, without needing you to create triggers, rule or defaults.
Types of constraints: NOT NULL, CHECK, UNIQUE, PRIMARY KEY, FOREIGN KEY
For an explanation of these constraints see books online for the pages titled: “Constraints” and “CREATE TABLE”, “ALTER TABLE”
Q.What is an index? What are the types of indexes? How many clustered indexes can be created on a table? I create a separate index on each column of a table. what are the advantages and disadvantages of this approach?
Answer: Indexes in SQL Server are similar to the indexes in books. They help SQL Server retrieve the data quicker.
Indexes are of two types. Clustered indexes and non-clustered indexes. When you craete a clustered index on a table, all the rows in the table are stored in the order of the clustered index key. So, there can be only one clustered index per table. Non-clustered indexes have their own storage separate from the table data storage. Non-clustered indexes are stored as B-tree structures (so do clustered indexes), with the leaf level nodes having the index key and it’s row locater. The row located could be the RID or the Clustered index key, depending up on the absence or presence of clustered index on the table.
If you create an index on each column of a table, it improves the query performance, as the query optimizer can choose from all the existing indexes to come up with an efficient execution plan. At the same t ime, data modification operations (such as INSERT, UPDATE, DELETE) will become slow, as every time data changes in the table, all the indexes need to be updated. Another disadvantage is that, indexes need disk space, the more indexes you have, more disk space is used.
Q.What is RAID and what are different types of RAID configurations?
Answer: RAID stands for Redundant Array of Inexpensive Disks, used to provide fault tolerance to database servers. There are six RAID levels 0 through 5 offering different levels of performance, fault tolerance. MSDN has some information about RAID levels and for detailed information, check out the RAID advisory board’s homepage.
Q.What are the steps you will take to improve performance of a poor performing query?
Answer: This is a very open ended question and there could be a lot of reasons behind the poor performance of a query. But some general issues that you could talk about would be: No indexes, table scans, missing or out of date statistics, blocking, excess recompilations of stored procedures, procedures and triggers without SET NOCOUNT ON, poorly written query with unnecessarily complicated joins, too much normalization, excess usage of cursors and temporary tables.
Some of the tools/ways that help you troubleshooting performance problems are: SET SHOWPLAN_ALL ON, SET SHOWPLAN_TEXT ON, SET STATISTICS IO ON, SQL Server Profiler, Windows NT /2000 Performance monitor, Graphical execution plan in Query Analyzer.
Download the white paper on performance tuning SQL Server from Microsoft web site. Don’t forget to check out sql-server-performance.com
Q.What are the steps you will take, if you are tasked with securing an SQL Server?
Answer: Again this is another open ended question. Here are some things you could talk about: Preferring NT authentication, using server, database and application roles to control access to the data, securing the physical database files using NTFS permissions, using an unguessable SA password, restricting physical access to the SQL Server, renaming the Administrator account on the SQL Server computer, disabling the Guest account, enabling auditing, using multiprotocol encryption, setting up SSL, setting up firewalls, isolating SQL Server from the web server etc.
Q.What is a deadlock and what is a live lock? How will you go about resolving deadlocks?
Answer: Deadlock is a situation when two processes, each having a lock on one piece of data, attempt to acquire a lock on the other’s piece. Each process would wait indefinitely for the other to release the lock, unless one of the user processes is terminated. SQL Server detects deadlocks and terminates one user’s process.
A livelock is one, where a request for an exclusive lock is repeatedly denied because a series of overlapping shared locks keeps interfering. SQL Server detects the situation after four denials and refuses further shared locks. A livelock also occurs when read transactions monopolize a table or page, forcing a write transaction to wait indefinitely.
Q.What is blocking and how would you troubleshoot it?
Answer: Blocking happens when one connection from an application holds a lock and a second connection requires a conflicting lock type. This forces the second connection to wait, blocked on the first.
Read up the following topics in SQL Server books online: Understanding and avoiding blocking, Coding efficient transactions.
Q.Explain CREATE DATABASE syntax
Answer: Many of us are used to craeting databases from the Enterprise Manager or by just issuing the command: CREATE DATABAE MyDB. But what if you have to create a database with two filegroups, one on drive C and the other on drive D with log on drive E with an initial size of 600 MB and with a growth factor of 15%? That’s why being a DBA you should be familiar with the CREATE DATABASE syntax. Check out SQL Server books online for more information.
Q.How to restart SQL Server in single user mode? How to start SQL Server in minimal configuration mode?
Answer: SQL Server can be started from command line, using the SQLSERVR.EXE. This EXE has some very important parameters with which a DBA should be familiar with. -m is used for starting SQL Server in single user mode and -f is used to start the SQL Server in minimal configuration mode. Check out SQL Server books online for more parameters and their explanations.
Q.As a part of your job, what are the DBCC commands that you commonly use for database maintenance?
Answer: DBCC CHECKDB, DBCC CHECKTABLE, DBCC CHECKCATALOG, DBCC CHECKALLOC, DBCC SHOWCONTIG, DBCC SHRINKDATABASE, DBCC SHRINKFILE etc. But there are a whole load of DBCC commands which are very useful for DBAs. Check out SQL Server books online for more information.
Q.What are statistics, under what circumstances they go out of date, how do you update them?
Answer: Statistics determine the selectivity of the indexes. If an indexed column has unique values then the selectivity of that index is more, as opposed to an index with non-unique values. Query optimizer uses these indexes in determining whether to choose an index or not while executing a query.

Some situations under which you should update statistics:
1) If there is significant change in the key values in the index
2) If a large amount of data in an indexed column has been added, changed, or removed (that is, if the distribution of key values has changed), or the table has been truncated using the TRUNCATE TABLE statement and then repopulated
3) Database is upgraded from a previous version
Look up SQL Server books online for the following commands: UPDATE STATISTICS, STATS_DATE, DBCC SHOW_STATISTICS, CREATE STATISTICS, DROP STATISTICS, sp_autostats, sp_createstats, sp_updatestats
Q.What are the different ways of moving data/databases between servers and databases in SQL Server?
Answer: There are lots of options available, you have to choose your option depending upon your requirements. Some of the options you have are: BACKUP/RESTORE, dettaching and attaching databases, replication, DTS, BCP, logshipping, INSERT…SELECT, SELECT…INTO, creating INSERT scripts to generate data.
Q.Explain different types of BACKUPs available in SQL Server? Given a particular scenario, how would you go about choosing a backup plan?
Answer: Types of backups you can create in SQL Sever 7.0+ are Full database backup, differential database backup, transaction log backup, filegroup backup. Check out the BACKUP and RESTORE commands in SQL Server books online. Be prepared to write the commands in your interview. Books online also has information on detailed backup/restore architecture and when one should go for a particular kind of backup.
Q.What is database replication? What are the different types of replication you can set up in SQL Server?
Answer: Replication is the process of copying/moving data between databases on the same or different servers. SQL Server supports the following types of replication scenarios:
Snapshot replication
Transactional replication (with immediate updating subscribers, with queued updating subscribers)
Merge replication
See SQL Server books online for indepth coverage on replication. Be prepared to explain how different replication agents function, what are the main system tables used in replication etc.

Q.How to determine the service pack currently installed on SQL Server?
Answer: The global variable @@Version stores the build number of the sqlservr.exe, which is used to determine the service pack installed. To know more about this process visit
Q.What are cursors? Explain different types of cursors. What are the disadvantages of cursors? How can you avoid cursors?
Answer: Cursors allow row-by-row processing of the resultsets.
Types of cursors: Static, Dynamic, Forward-only, Keyset-driven. See books online for more information.
Disadvantages of cursors: Each time you fetch a row from the cursor, it results in a network roundtrip, where as a normal SELECT query makes only one rowundtrip, however large the resultset is. Cursors are also costly because they require more resources and temporary storage (results in more IO operations). Furthere, there are restrictions on the SELECT statements that can be used with some types of cursors.
Most of the times, set based operations can be used instead of cursors. Here is an example:
If you have to give a flat hike to your employees using the following criteria:
Salary between 30000 and 40000 — 5000 hike
Salary between 40000 and 55000 — 7000 hike
Salary between 55000 and 65000 — 9000 hike
In this situation many developers tend to use a cursor, determine each employee’s salary and update his salary according to the above formula. But the same can be achieved by multiple update statements or can be combined in a single UPDATE statement as shown below:
UPDATE tbl_emp SET salary =
CASE WHEN salary BETWEEN 30000 AND 40000 THEN salary + 5000
WHEN salary BETWEEN 40000 AND 55000 THEN salary + 7000
WHEN salary BETWEEN 55000 AND 65000 THEN salary + 10000
END
Another situation in which developers tend to use cursors: You need to call a stored procedure when a column in a particular row meets certain condition. You don’t have to use cursors for this. This can be achieved using WHILE loop, as long as there is a unique key to identify each row.
Q.Write down the general syntax for a SELECT statements covering all the options
Answer: Here’s the basic syntax: (Also checkout SELECT in books online for advanced syntax).
SELECT select_list
[INTO new_table_]
FROM table_source
[WHERE search_condition]
[GROUP BY group_by_expression]
[HAVING search_condition]
[ORDER BY order_expression [ASC | DESC] ]
Q.What is a join and explain different types of joins
Answer: Joins are used in queries to explain how different tables are related. Joins also let you select data from a table depending upon data from another table.
Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs.OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.
Q.Can you have a nested transaction?
Answer: Yes, very much. Check out BEGIN TRAN, COMMIT, ROLLBACK, SAVE TRAN and @@TRANCOUNT
Q.What is an extended stored procedure? Can you instantiate a COM object by using T-SQL?
Answer: An extended stored procedure is a function within a DLL (written in a programming language like C, C++ using Open Data Services (ODS) API) that can be called from T-SQL,just the way we call normal stored procedures using the EXEC statement. See books online to learn how to create extended stored procedures and how to add them to SQL Server.
Yes, you can instantiate a COM (written in languages like VB, VC++) object from T-SQL by using sp_OACreate stored procedure. Also see books online for sp_OAMethod, sp_OAGetProperty, sp_OASetProperty, sp_OADestroy.
Q.What is the system function to get the current user’s user id?
Answer: USER_ID().Also check out other system functions like USER_NAME(), SYSTEM_USER, SESSION_USER, CURRENT_USER, USER, SUSER_SID(), HOST_NAME().
Q.What are triggers? How many triggers you can have on a table? How to invoke a trigger on demand?
Answer: Triggers are special kind of stored procedures that get executed automatically when an INSERT, UPDATE or DELETE operation takes place on a table.
In SQL Server 6.5 you could define only 3 triggers per table, one for INSERT, one for UPDATE and one for DELETE. From SQL Server 7.0 onwards, this restriction is gone, and you could create multiple triggers per each action. But in 7.0 there’s no way to control the order in which the triggers fire. In SQL Server 2000 you could specify which trigger fires first or fires last using sp_settriggerorder
Triggers can’t be invoked on demand. They get triggered only when an associated action (INSERT, UPDATE, DELETE) happens on the table on which they are defined.
Triggers are generally used to implement business rules, auditing. Triggers can also be used to extend the referential integrity checks, but wherever possible, use constraints for this purpose, instead of triggers, as constraints are much faster.
Till SQL Server 7.0, triggers fire only after the data modification operation happens. So in a way, they are called post triggers. But in SQL Server 2000 you could create pre triggers also. Search SQL Server 2000 books online for INSTEAD OF triggers.
Q.There is a trigger defined for INSERT operations on a table, in an OLTP system. The trigger is written to instantiate a COM object and pass the newly insterted rows to it for some custom processing. What do you think of this implementation? Can this be implemented better?
Answer:  Instantiating COM objects is a time consuming process and since you are doing it from within a trigger, it slows down the data insertion process. Same is the case with sending emails from triggers. This scenario can be better implemented by logging all the necessary data into a separate table, and have a job which periodically checks this table and does the needful.
Q.What is a self join? Explain it with an example
Answer: Self join is just like any other join, except that two instances of the same table will be joined in the query. Here is an example: Employees table which contains rows for normal employees as well as managers. So, to find out the managers of all the employees, you need a self join.
CREATE TABLE emp
(
empid int,
mgrid int,
empname char(10)
)
INSERT emp SELECT 1,2,’Vyas’
INSERT emp SELECT 2,3,’Mohan’
INSERT emp SELECT 3,NULL,’Shobha’
INSERT emp SELECT 4,2,’Shridhar’
INSERT emp SELECT 5,2,’Sourabh’
SELECT t1.empname [Employee], t2.empname [Manager]
FROM emp t1, emp t2
WHERE t1.mgrid = t2.empid
Here’s an advanced query using a LEFT OUTER JOIN that even returns the employees without managers (super bosses)
SELECT t1.empname [Employee], COALESCE(t2.empname, ‘No manager’) [Manager]
FROM emp t1
LEFT OUTER JOIN
emp t2
ON
t1.mgrid = t2.empid

contact for more on Oracle Sql Plsql Online Training

Oracle Sql Plsql Interview Questions Overall rating: ★★★★☆ 4.4 based on 427 reviews
5 1

oracle sql plsql interview questions

Write A Review 

Name
Email
Review Title
Rating
Review Content

Oracle Sql Plsql Interview Questions Tags

oracle sql plsql interview questions and answers,oracle sql plsql online training, oracle sql plsql interview questions, oracle sql plsql training online, oracle sql plsql training, oracle sql plsql training institute, latest oracle sql plsql interview questions, best oracle sql plsql interview questions 2019, top 100 oracle sql plsql interview questions,sample oracle sql plsql interview questions,oracle sql plsql interview questions technical, best oracle sql plsql interview tips, best oracle sql plsql interview basics, oracle sql plsql Interview techniques, oracle sql plsql Interview Tips.

For  online training videos