SQL_INTERVIEW_QUESTIONS_WITH_ANSWERS
SQL_INTERVIEW_QUESTIONS_WITH_ANSWERS
SQL_INTERVIEW_QUESTIONS_WITH_ANSWERS
An outer join includes rows from tables when there are no matching values in the tables.
Subselect is a select which works in conjunction with another select. A nested select is a
kind of subselect where the
inner select passes to the where criteria for the outer select.
Group by controls the presentation of the rows, order by controls the presentation of the
columns for the results of the
SELECT statement.
What keyword does an SQL SELECT statement use for a string search?
The LIKE keyword allows for string searches. The % sign is used as a wildcard.
The common aggregate, built-in functions are AVG, SUM, MIN, MAX, COUNT and
DISTINCT.
SUBSTR is used for string manipulation with column name, first position and string length
used as arguments. E.g.
SUBSTR (NAME, 1 3) refers to the first three characters in the column NAME.
The explain statement provides information about the optimizer's choice of access path of
the SQL.
Referential integrity refers to the consistency that must be maintained between primary
and foreign keys, i.e. every
foreign key value must have a corresponding primary key value.
What is a NULL value? What are the pros and cons of using NULLS?
A NULL value takes up one byte of storage and indicates that a value is not present as
opposed to a space or zero
value. It's the DB2 equivalent of TBD on an organizational chart and often correctly
portrays a business situation.
Unfortunately, it requires extra coding for an application program to handle this situation.
A synonym is used to reference a table or view by another name. The other name can
then be written in the
application code pointing to test tables in the development stage and to production
entities when the code is migrated.
qualifier of a table or view. The alias is not dropped when the table is dropped.
When can an insert of a new primary key value threaten referential integrity?
Never. New primary key values are not a problem. However, the values of foreign key
inserts must have
corresponding primary key values in their related tables. And updates of primary key
values may require changes in
the program must dynamically allocate memory to receive the query results.
Any sub select can be rewritten as a join, but not vice versa. Joins are usually more
efficient as join rows can be
Returned immediately, subselects require a temporary work area for inner selects results
while processing the outer
select.
What is the difference between IN sub selects and EXISTS sub select?
If there is an index on the attributes tested an IN is more efficient since DB2 uses the
index for the IN. (IN for index is
he mnemonic).
Cartesian product results from a faulty query. It is a row in the results for every
combination in the join tables.
What is a tuple?
Static SQL is compiled and optimized prior to its execution; dynamic is compiled and
optimized during execution.
Any SQL implementation covers data types in couple of main categories. Which of
the following are those data
A). NUMERIC
B). CHARACTER
C). DATE AND TIME
A,B,C. Not all SQL implementations have a BLOB or a BIT data types.
We have a table with a CHARACTER data type field. We apply a ">" row
comparison between this field and
nother CHARACTER field in another table. What will be the results for records with
field value of NULL?
TRUE
B. FALSE
C. UNKNOWN
D. Error.
Any database needs to go through a normalization process to make sure that data
is represented only once. This
will eliminate problems with creating or destroying data in the database. The
normalization process is done
usually in three steps which results in first, second and third normal forms. Which
best describes the process to
obtain the third normal form? (Check one that applies the best)
We have a table with multi-valued key. All columns that are dependent on only one or on
some of the keys should be moved in a different table.
If a table has columns not dependent on the primary keys, they need to be moved in a
separate table.
E. Primary key is always UNIQUE and NOT NULL.
D. All columns in a table should be dependent on the primary key. This will eliminate
transitive dependencies in
which A depends on B, and B depends on C, but we're not sure how C depends on A.
the most important pre-defined structures for this mechanism are SQLDA ("SQL
Descriptor Area") and
SQLSTATE is a standard set of error messages and warnings in which the first two
characters defines the class
and the last three defines the subclass of the error. Which of the following
SQLSTATE codes is interpreted as
A). 00xxx
B). 01xxx
C). 02xxx
D). 22xxx
E). 2Axxx
The SQL source is contained in host variables rather than being hard coded into the
program. The SQL statement may
They are SQL statements that are embedded with in application program and are
prepared during the program
preparation process before the program is executed. After it is prepared, the statement
itself does not change(although
What is a join?
A join is a relational operation that allows retrieval of data from two or more tables based
on matching columns
values.
What is an object?
An object is anything that is managed by DB2 (that is databases, table spaces, tables,
views, indexes or synonyms), but
Not the data itself.
How would you find out the total number of rows in a table? - GS
Use SELECT COUNT (*)...
How do you retrieve the first 5 characters of FIRSTNAME column of EMP table?
SELECT SUBSTR(FIRSTNAME,1,5) FROM EMP;
How do you concatenate the FIRSTNAME and LASTNAME from EMP table to give a
complete name?
SELECT FIRSTNAME || ' ' || LASTNAME FROM EMP;
Suppose I have five SQL SELECT statements connected by UNION/UNION ALL, how
many times should I
specify UNION to eliminate the duplicate rows? - GS
Once.
What is 'LIKE' used for in WHERE clause? What are the wildcard characters? - GS
LIKE is used for partial string matches. '%' ( for a string of any character ) and '_' (for any
single character ) are the
two wild card characters.
Consider the employee table with column PROJECT nullable. How can you get a
list of employees who are not
assigned to any project?
SELECT EMPNO FROM EMP WHERE PROJECT IS NULL;
How would you retrieve rows from a DB2 table in embedded SQL? - GS
Either by using the single row SELECT statements,or by using the CURSOR.
Apart from cursor, what other ways are available to you to retrieve a row from a
table in embedded SQL? - GS
Single row SELECTs.
Can you have more than one cursor open at any one time in a program ? - GS
Yes.
What RDMS objects are required before you can create a table?
Before you can create a table, you need an existing database and tablespace.
Which RDMS objects can you change with the SQL ALTER statements?
The SQL ALTER statement can change a table index, a table, a tablespace, or a
STOGROUP.
What is a synonym?
A foreign key is the key defined in one table to reference the primary key of a reference
table. This foreign key must
have the same structure as the reference table’s primary key.
What is a cursor?
A cursor is a named control structure used to make a set of rows available to a program.
DB2 is the relational database
system that runs in an MVS environment. It was developed by IBM and interfaces
with SQL. With the use of SQL
DB2, databases can be accessed by a wide range of host languages. SQL is the
relational database " application
language " that interfaces with DB2. Because of its capabilities, SQL and, in turn,
DB2 have gained considerable
acceptance. Thus, a working knowledge of DB2 increases one's marketability.
What techniques are used to retrieve data from more than one table in a single SQL
statement?
Joins, unions and nested selects are used to retrieve data.
What are the Back ground processes in Oracle and what are they?
This is one of the most frequently asked question. There are basically 9 Processes but in
a general system we need to mention the first five background processes. They do the
house keeping activities for the Oracle and are common in any system.
The various background processes in oracle are
a) Data Base Writer (DBWR): Data Base Writer Writes Modified blocks from Database
buffer cache to Data Files. This is required since the data is not written whenever a
transaction is committed.
b)LogWriter (LGWR) : LogWriter writes the redo log entries to disk. Redo Log data is
generated in redo log buffer of SGA. As transaction commits and log buffer fills, LGWR
writes log entries into a online redo log file.
c) System Monitor(SMON) : The System Monitor performs instance recovery at instance
startup. This is useful for recovery from system failure
d)Process Monitor(PMON) : The Process Monitor performs process recovery when user
Process fails. Pmon Clears and Frees resources that process was using.
e) CheckPoint(CKPT) : At Specified times, all modified database buffers in SGA are
written to data files by DBWR at Checkpoints and Updating all data files and control files
of database to indicate the
most recent checkpoint
f)Archieves(ARCH) : The Archiver copies online redo log files to archival storal when they
are busy.
g) Recoveror(RECO) : The Recoveror is used to resolve the distributed transaction in
network
h) Dispatcher (Dnnn) : The Dispatcher is useful in Multi Threaded Architecture
i) Lckn : We can have upto 10 lock processes for inter instance locking in parallel sql.