Basics and Fundamentals

Estimated reading: 2 minutes 22 views

1. What is SQL, and why is it important for functional testing?

SQL (Structured Query Language) is used to interact with databases. In functional testing, SQL is important to:

  • Validate backend data operations.
  • Verify data correctness after test execution.
  • Prepare test data or clean up post-testing.
  • Test database integrity and relationships.
  • Debug issues with data mismatches.

2. Difference Between DDL, DML, and DCL with Examples

CategoryPurposeKey CommandsExample
DDLDefine database structureCREATE, ALTER, DROPCREATE TABLE employees (id INT, name VARCHAR);
DMLManipulate dataINSERT, UPDATE, DELETEINSERT INTO employees VALUES (1, 'Alice');
DCLManage permissionsGRANT, REVOKEGRANT SELECT ON employees TO tester;
  • DDL: Changes structure, auto-committed.
  • DML: Modifies data, requires commit.
  • DCL: Manages user permissions.

3. Write a query to fetch specific columns from a table

To fetch specific columns, use the SELECT statement followed by the column names you need.
Example:

				
					SELECT name, role FROM employees;

				
			

4. How do you retrieve all rows and columns from a table?

				
					SELECT * FROM employees;

				
			

5. What is the use of aliases (AS keyword) in a SELECT statement?

Aliases are used to rename columns or tables for better readability or to simplify complex names.
Example:

				
					SELECT name AS EmployeeName FROM employees;

				
			

6. How do you use mathematical expressions or calculated fields in a SELECT query?

You can use arithmetic operators or functions to perform calculations directly in the SELECT query.
Example:

				
					SELECT name, salary * 12 AS AnnualSalary FROM employees;

				
			

7. Write a query to combine columns from multiple tables using a JOIN

Use the JOIN clause to combine rows from two or more tables based on a related column.
Example:

				
					SELECT e.name, d.department_name 
FROM employees e 
JOIN departments d 
ON e.department_id = d.id;

				
			

8. How can you fetch the first N rows from a table using SQL?

In Oracle, use ROWNUM to limit the number of rows returned.
Example:

				
					SELECT * FROM employees WHERE ROWNUM <= 5;

				
			

Leave a Comment

Share this Doc

Basics and Fundamentals

Or copy link

CONTENTS