SQL Interview Questions For Software Testers
SQL Interview Questions For Software Testers
Private Database Link, Public Database Link & Network Database Link.
Private database link is created on behalf of a specific user. A private database link can be used only
when the owner of the link specifies a global object name in a SQL statement or in the definition of
the owner's views or procedures.
Public database link is created for the special user group PUBLIC. A public database link can be
used when any user in the associated database specifies a global object name in a SQL statement or
object definition.
Network database link is created and managed by a network domain service. A network database
link can be used when any user of any database in the network specifies a global object name in a
SQL statement or object definition.
Q. Which is more faster - IN or EXISTS?
EXISTS is more faster than IN because EXISTS returns a Boolean value whereas IN returns a
value.
Q. What is a join?
A. Join is a process of retrieve pieces of data from different sets (tables) and returns them to the
user or program as one oejoined collection of data.
Types of Joins
Equijoins
Non-equijoins
Outer joins
Self joins
Cross joins
Natural joins
Full or outer joins
Equijoins
To determine an employees department name, you compare the value in the DEPARTMENT_ID
column in the EMPLOYEES table with the DEPARTMENT_ID values in the DEPARTMENTS
table. The relationship between the EMPLOYEES and DEPARTMENTS tables is an equijointhat
is, values in the DEPARTMENT_ID column
on both tables must be equal. Frequently, this type of join involves primary and foreign key
complements.
Note: Equijoins are also called simple joins or inner joins.
Non-Equijoins
A non-equijoin is a join condition containing something other than an equality operator.
The relationship between the EMPLOYEES table and the JOB_GRADES table has an
example of a non-equijoin. A relationship between the two tables is that the SALARY
column in the EMPLOYEES table must be between the values in the LOWEST_SALARY
and HIGHEST_SALARY columns of the JOB_GRADES table. The relationship is
obtained using an operator other than equals (=).
SELECT e.last_name, e.salary, j.grade_level
FROM employees e, job_grades j
WHERE e.salary
BETWEEN j.lowest_sal AND j.highest_sal;
Outer join : to also see rows that do not meet the join condition
Q. What is Normalization?
A. The process of table design is called normalization.
Q. What is referential integrity constraints?
A. Referential integrity constraints are rules
that are partnof the table in a database schema.
Q. What is Trigger?
A. Trigger will execute a block of procedural code against the database when a table event occurs.
A2. A trigger defines a set of actions that are performed in response
to an insert, update, or delete operation on a specified table. When such an SQL operation is
executed, in this case the trigger has been activated.
Q. Which of the following WHERE clauses will return only rows
that have a NULL in the PerDiemExpenses column?
A. WHERE PerDiemExpenses <>
B. WHERE PerDiemExpenses IS NULL
C. WHERE PerDiemExpenses = NULL
D. WHERE PerDiemExpenses NOT IN (*)
A. B is correct When searching for a NULL value in a column, you must
use the keyword IS. No quotes are required around the keyword NULL.
22. Q. You issue the following query:SELECT FirstName FROM
StaffListWHERE FirstName LIKE'_A%'Which names would be
returned by this query? Choose all that apply.
A. Allen
B. CLARK
C. JACKSON
D. David
A. C is correct Two wildcards are used with the LIKE operator.
The underscore (_) stands for any one character of any
case, and the percent sign (%) stands for any number of
characters of any case including none. Because this string
starts with an underscore rather than a percent sign, it won't
return Allen or Clark because they represent zero and two
characters before the "A". If the LIKE string had been "%A%",
both of these values would have been returned.
David was not returned because all non-wild card characters
are case sensitive. Therefore, only strings
with an uppercase "A" as their second letter are returned
Q. Write a SQL SELECT query that only returns each city only once from Students table?
Do you need to order this list with an ORDER BY clause?
A. SELECT DISTINCT City FROM Students;
The Distinct keyword automatically sorts all data
in ascending order. However, if you want the data
sorted in descending order, you have to use an ORDER BY clause
Q. Is the WHERE clause must appear always before the GROUP BY clause in SQL SELECT ?
A. Yes.
The proper order for SQL SELECT
clauses is: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY.
Only the SELECT and FROM clause are mandatory.
Q. How Oracle executes a statement with nested subqueries?
A. When Oracle executes a statement with nested subqueries,
it always executes the innermost query first. This query passes its
results to the next query and so on until it reaches the outermost query.
It is the outermost query that returns a result set.
Q. Which operator do you use to return all of the rows
from one query except rows are returned in a second query?
A. You use the MINUS operator to return all rows from one query except
where duplicate rows are found in a second query. The UNION operator
returns all rows from both queries minus duplicates. The UNION ALL operator
returns all rows from both queries including duplicates.
The INTERSECT operator returns only those rows that exist in both queries.
Q. How you will create a column alias? (Oracle 8i)
A. The AS keyword is optional when specifying a column alias.
You must enclose the column alias in double quotes when the alias
contains a space or lowercase letters. If you specify an alias in l
owercase letters without double quotes, the alias will appear in uppercase.
Q. Which of the following statements are Data Manipulation Language commands?
A. INSERT
B. UPDATE
C. GRANT
D. TRUNCATE
E. CREATE
A. A and B The INSERT and UPDATE statements are
Data Manipulation Language (DML) commands.
GRANT is a Data Control Language (DCL) command.
TRUNCATE and CREATE are Data Definition Language (DDL) commands
Q. What is Oracle locking?
A. Oracle uses locking mechanisms to protect data from
being destroyed by concurrent transactions.
Q. What Oracle lock modes do you know?
A. Oracle has two lock modes: shared or exclusive.
Shared locks are set on database resources so that many transactions
can access the resource.
Exclusive locks are set on resources that ensure
one transaction has exclusive access to the database resource
TRUNCATE - remove all records from a table, including all spaces allocated for
the records are removed
COMMENT - add comments to the data dictionary
GRANT - gives user's access privileges to database
REVOKE - withdraw access privileges given with the GRANT command
DML is Data Manipulation Language statements. Some examples:
SELECT - retrieve data from the a database
INSERT - insert data into a table
UPDATE - updates existing data within a table
DELETE - deletes all records from a table, the space for the records remain
CALL - call a PL/SQL or Java subprogram
EXPLAIN PLAN - explain access path to data
LOCK TABLE - control concurrency
DCL is Data Control Language statements. Some examples:
COMMIT - save work done
SAVEPOINT - identify a point in a transaction to which you can later roll back
ROLLBACK - restore database to original since the last COMMIT
SET TRANSACTION - Change transaction options like what rollback segment to use
Can we drop a column from a table?
yes. ALTER TABLE table_name DROP COLUMN column_name;
Q. Describe some Group Functions that you know
A. 1) The COUNT function tells you how many rows were in the result set.
SELECT COUNT(*) FROM TESTING.QA
2) The AVG function tells you the average value of a numeric column.
SELECT MAX(SALARY) FROM TESTING.QA
3) The MAX and MIN functions tell you the maximum and minimum value of a numeric column.
SELECT MIN(SALARY) FROM TESTING.QA
4) The SUM function tells you the sum value of a numeric column.
SELECT SUM(SALARY) FROM TESTING.QA
Group functions: Group functions operate on sets of rows to give one result per group
Count function : COUNT(*) returns the number of rows in a table.
SELECT COUNT(*)FROM employees
WHERE department_id = 50;
Having clause
If you restrict rows based on the result of a group function, you must have a GROUP BY clause as
well as the HAVING clause.
SELECT department_id, MAX(salary)
FROM employees
GROUP BY department_id
HAVING MAX(salary)>10000 ;