SQL Interview Questions
SQL Interview Questions
Q. What is a join?
Join is a process of retrieve pieces of data from different sets (tables) and returns them to the user or
program as one “joined” collection of data.
Q. List all the possible values that can be stored in a BOOLEAN data field.
There are only two values that can be stored in a BOOLEAN data field: -1(true) and 0(false).
Q. What is the highest value that can be stored in a BYTE data field?
A. The highest value that can be stored in a BYTE field is 255. or from -128 to 127. Byte is a set of Bits
that represent a single character. Usually there are 8 Bits in a Byte, sometimes more, depending on
how the measurement is being made. Each Char requires one byte of memory and can have a value
from 0 to 255 (or 0 to 11111111 in binary).
Q. What is Normalization?
A. The process of table design is called normalization.
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. 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;
Q. Write SQL SELECT query that returns the first and last name of each instructor, the Salary, and
gives each of them a number.
A. SELECT FirstName, LastName, Salary, ROWNUM FROM Instructors;
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.
3. 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 “joined†collection of data.
Exp:
outer joint
cross-join
self join
SELECT e1.name | |’ ‘ | | e2.ename FROM emp e1, emp e2 WHERE e1. emp_no =
e2.emp_no;
The result of T1 INNER JOIN T2 consists of their paired rows where the
join-condition is true.
The result of T1 LEFT OUTER JOIN T2 consists of their paired rows where
the join-condition is true and, for each unpaired row of T1, the
concatenation of that row with the null row of T2. All columns derived
where the join-condition is true and, for each unpaired row of T2, the
concatenation of that row with the null row of T1. All columns derived
for each unpaired row of T2, the concatenation of that row with the null
row of T1 and, for each unpaired row of T1, the concatenation of that row
with the null row of T2. All columns derived from T1 and T2 allow null
values.
A. UPDATE EMP_table
A. The main role of a primary key in a data table is to maintain the internal integrity of
a data table.
12. Q. Can a table have more than one foreign key defined?
A. A table can have any number of foreign keys defined. It can have only
13. Q. List all the possible values that can be stored in a BOOLEAN data field.
A. There are only two values that can be stored in a BOOLEAN data field:
14 Q. What is the highest value that can be stored in a BYTE data field?
A. The highest value that can be stored in a BYTE field is 255. or from -128
the measurement is being made. Each Char requires one byte of memory
A. The CURRENCY data type can store up to four places to the right of the
decimal. Any data beyond the fourth place will be truncated by Visual
such an SQL operation is executed, in this case the trigger has been
activated.
21. Q. Which of the following WHERE clauses will return only rows
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.
A. Allen
B. CLARK
C. JACKSON
D. David
A. C is correct � Two wildcards are used with the LIKE operator.
case, and the percent sign (%) stands for any number of
characters of any case including none. Because this string
characters before the "A". If the LIKE string had been "%A%",
23. Q. Write a SQL SELECT query that only returns each city only once from Students
table?
FROM Students;
26. Q. Write SQL SELECT example how you limiting the rows returned with a WHERE
clause.
27. Q. Write SQL SELECT query that returns the first and
28. Q. Which of the following functions can be used only with numeric values?
A. AVG
B. MIN
C. LENGTH
D. SUM
E. ROUND
A. RTRIM
B. RPAD
C. TRIM
TRIM function
31. Q. Is the WHERE clause must appear always before the GROUP BY clause in SQL
SELECT ?
A. Yes.
clauses is: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY.
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.
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
The INTERSECT operator returns only those rows that exist in both queries.
34. Q. How you will create a column alias? (Oracle 8i)
You must enclose the column alias in double quotes when the alias
owercase letters without double quotes, the alias will appear in uppercase.
A. INSERT
B. UPDATE
C. GRANT
D. TRUNCATE
E. CREATE
39. Question. What are the main components of Database management systems
software.
40. Question. What are the main attributes of database management system?
it consists from:
BEGIN-TRANSACTION Name
Code
Informix
DB2
SQL
Oracle
select j.FILE_NUM
Answer: j and a aliases for table names. this is outer joint select statament from two
tables.
44. Q. Describe some Conversion Functions that you know
A. 1) The COUNT function tells you how many rows were in the result set.
2) The AVG function tells you the average value of a numeric column.
3) The MAX and MIN functions tell you the maximum and minimum value of a
numeric column.
A. The clauses of the subselect are processed in the following sequence (DB2):
1. FROM clause
2. WHERE clause
3. GROUP BY clause
4. HAVING clause
5. SELECT clause
6. ORDER BY clause
52. Question:
Write SQL query to see the result as a text definitions that is corresponded
case TB1.status
else TB_name.status
end
where
order by TB1.member_id
53. Question:
What's the logical difference, if any, between the following SQL expressions?
A. They're the same unless table T is empty, in which case the first yields
a one-column, one-row table containing a zero and the second yields a one-column,
3. 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 “joined†collection of data.
cross-join
SELECT * FROM table1, table2;
self join
SELECT e1.name | |’ ‘ | | e2.ename FROM emp e1, emp e2 WHERE e1. emp_no =
e2.emp_no;
• The result of T1 INNER JOIN T2 consists of their paired rows where the
join-condition is true.
• The result of T1 LEFT OUTER JOIN T2 consists of their paired rows where
the join-condition is true and, for each unpaired row of T1, the
concatenation of that row with the null row of T2. All columns derived
from T2 allow null values.
• The result of T1 RIGHT OUTER JOIN T2 consists of their paired rows
where the join-condition is true and, for each unpaired row of T2, the
concatenation of that row with the null row of T1. All columns derived
from T1 allow null values.
• The result of T1 FULL OUTER JOIN T2 consists of their paired rows and,
for each unpaired row of T2, the concatenation of that row with the null
row of T1 and, for each unpaired row of T1, the concatenation of that row
with the null row of T2. All columns derived from T1 and T2 allow null
values.
12. Q. Can a table have more than one foreign key defined?
A. A table can have any number of foreign keys defined. It can have only
one primary key defined.
13. Q. List all the possible values that can be stored in a BOOLEAN data field.
A. There are only two values that can be stored in a BOOLEAN data field:
-1(true) and 0(false).
14 Q. What is the highest value that can be stored in a BYTE data field?
A. The highest value that can be stored in a BYTE field is 255. or from -128
to 127. Byte is a set of Bits that represent a single character.
Usually there are 8 Bits in a Byte, sometimes more, depending on how
the measurement is being made. Each Char requires one byte of memory
and can have a value from 0 to 255 (or 0 to 11111111 in binary).
15. Q. How many places to the right of the decimal can be stored in a
CURRENCY data field?
A. The CURRENCY data type can store up to four places to the right of the
decimal. Any data beyond the fourth place will be truncated by Visual
Basic without reporting an error.
21. 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.
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
23. 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?
26. Q. Write SQL SELECT example how you limiting the rows returned with a WHERE clause.
27. Q. Write SQL SELECT query that returns the first and
last name of each instructor, the Salary,
and gives each of them a number.
28. Q. Which of the following functions can be used only with numeric values?
(Choose all that apply.)
A. AVG
B. MIN
C. LENGTH
D. SUM
E. ROUND
31. 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.
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.
39. Question. What are the main components of Database management systems software.
A. The database management system software includes
components for storage management, concurrency control, transaction
processing, database manipulation interface, database definition interface,
and database control interface.
40. Question. What are the main attributes of database management system?
A. A database management system is composed of five elements: computer hardware,
software, data, people (users), and operations procedures.
41. Question. What is transaction?
A. A transaction is a collection of applications
code and database manipulation code bound into an indivisible unit of execution.
it consists from:
BEGIN-TRANSACTION Name
Code
END TRANSACTION Name
Answer: j and a aliases for table names. this is outer joint select statament from two tables.
TO_NUMBER converts a character string containing digits to a numeric data type, it accepts
one parameter which is a column value or a string literal
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
A. The clauses of the subselect are processed in the following sequence (DB2):
1. FROM clause
2. WHERE clause
3. GROUP BY clause
4. HAVING clause
5. SELECT clause
6. ORDER BY clause
7. FETCH FIRST clause