Google

SQL Interview Questions For Software Testers

1. Q. What does SQL stand for?
A. Structured Query Language

2. Q. How do you select all records from the table?
A. Select * from table_name;

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.

4. Q. What kinds of joins do you know? Give examples.
A. We have self join, outer joint (LEFT, RIGHT), , cross-join ( Cartesian product n*m rows returned)
Exp:
outer joint
SELECT Employee.Name, Department. DeptName
FROM Employee, Department
WHERE Employee.Employee_ID = Department.Employee_ID;

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 following summarizes the result of the join operations:

• 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.

5. Q. How do you add record to a table?
A. INSERT into table_name VALUES (‘ALEX’ , 33 , ‘M’);


6. Q. How do you add a column to a table?
A. ALTER TABLE Department
ADD (AGE, NUMBER);

7. Q. How do you change value of the field?
A. UPDATE EMP_table
set number = 200 where item_munber = ‘CD’;

update name_table set status = 'enable' where phone = '4161112222';

update SERVICE_table set REQUEST_DATE = to_date ('2006-03-04 09:29', 'yyyy-mm-dd hh24:MI') where phone = '4161112222';

8. Q. What does COMMIT do?
A. Saving all changes made by DML statements

9. Q. What is a primary key?
A. The column (columns) that has completely unique data throughout
the table is known as the primary key field.

10. Q. What are foreign keys?
A. Foreign key field – is a field that links one table
to another table’s primary or foreign key.

11. Q. What is the main role of a primary key in a 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
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.

16. Q. What is a stored procedure?
A. A procedure is a group of PL/SQL statements that can be called by
a name. Procedures do not return values they perform tasks.

17. Q. Describe how NULLs work in SQL?
A. The NULL is how SQL handles missing values.
Arifthmetic operation with NULL in SQL will return a NULL.

18. Q. What is Normalization?
A. The process of table design is called normalization.

19. Q. What is referential integrity constraints?
A. Referential integrity constraints are rules
that are partnof the table in a database schema.

20. 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.

No comments: