Multiple Choice Questions (MCQs)
1. Who developed SQL and when?
a) Microsoft in 1980
b) Oracle in 1974
c) IBM in the early 1970s
d) MySQL in 1990
2. Which SQL standard was first introduced by ANSI?
a) SQL-92
b) SQL-86
c) SQL:1999
d) SQL:2011
3. Which of the following is NOT a numeric type in PostgreSQL?
a) INTEGER
b) SMALLINT
c) CHAR
d) NUMERIC
4. What does the CREATE DATABASE statement do?
a) Deletes a database
b) Updates a database
c) Creates a new database
d) Connects to a database
5. Which of the following operators is a logical operator in PostgreSQL?
a) =
b) <>
c) AND
d) >=
6. What is the purpose of the ORDER BY clause in SQL?
a) To limit the number of rows returned
b) To sort the rows in the result set
c) To update the rows in the table
d) To delete rows from a table
7. Which data type is used to store date and time in PostgreSQL?
a) DATE
b) TIME
c) TIMESTAMP
d) All of the above
8. Which function returns the current date in PostgreSQL?
a) NOW()
b) CURRENT_DATE
c) DATE_PART()
d) CURRENT_TIMESTAMP
9. What does the CONCAT() function do in PostgreSQL?
a) Returns the length of a string
b) Converts a string to uppercase
c) Joins two or more strings together
d) Replaces part of a string
10. Which of the following constraints ensures that a column cannot have a NULL value?
a) PRIMARY KEY
b) FOREIGN KEY
c) NOT NULL
d) UNIQUE
Short Questions
1. Define SQL and mention its significance in database management.
2. List any three versions of SQL introduced after SQL-86.
3. What are the ACID properties in SQL? Explain briefly.
4. Explain the difference between CHAR and VARCHAR in PostgreSQL.
5. Write the syntax to create a database named student_db in PostgreSQL.
6. How does the UPDATE statement work in PostgreSQL? Provide an example.
7. What is the difference between NOW() and CURRENT_DATE in PostgreSQL?
8. Write a SQL query to insert the name “John” and age 25 into a table named person.
9. What is the difference between AND and OR operators in SQL?
10. Explain the use of the LIMIT and OFFSET clauses with an example.
Long Questions
1. Explain the history and evolution of SQL.
2. Describe the lexical structure of SQL in PostgreSQL with suitable examples.
3. Discuss the various data types available in PostgreSQL with examples.
4. Write and explain the syntax and usage of INSERT, UPDATE, and DELETE statements in
PostgreSQL.
5. Explain the concept of Common Table Expressions (CTE) in PostgreSQL with an
example.
6. Describe the different types of operators available in PostgreSQL. Provide examples for
logical and comparison operators.
7. Explain the use of string functions such as LENGTH(), UPPER(), LOWER() and
CONCAT() with examples.
8. Write a SQL query to create a table named employees with columns id, name, salary, and
department. Include appropriate data types and constraints.
9. Discuss the significance of transaction management in SQL. How does PostgreSQL handle
transaction control?
10. Explain the use of ORDER BY, LIMIT, and OFFSET in SQL. Provide an example query
to demonstrate their usage.
11. Which clause is used to filter records based on a condition in SQL?
a) WHERE
b) FILTER
c) ORDER BY
d) LIMIT
12. What is the output of the following query?
SELECT CEIL(4.3);
a) 4
b) 5
c) 4.3
d) 6
13. In PostgreSQL, which keyword is used to switch between databases?
a) SWITCH
b) \c
c) CHANGE
d) CONNECT
14. What type of SQL statement is used to modify data in a table?
a) INSERT
b) DELETE
c) UPDATE
d) SELECT
15. Which of the following is not a character type in PostgreSQL?
a) CHAR
b) VARCHAR
c) TEXT
d) INTEGER
16. What does the NOW() function return in PostgreSQL?
a) Current time
b) Current date
c) Current date and time
d) None of the above
17. Which operator is used to compare values in SQL?
a) =
b) !=
c) <>
d) All of the above
18. Which SQL statement is used to delete all rows from a table without deleting the table
structure?
a) DROP
b) DELETE
c) TRUNCATE
d) REMOVE
19. Which type of JOIN returns all rows when there is a match in either table?
a) INNER JOIN
b) OUTER JOIN
c) LEFT JOIN
d) RIGHT JOIN
20. In PostgreSQL, what is the purpose of the SERIAL data type?
a) To store large text data
b) To automatically generate a unique number
c) To store date values
d) To store floating-point values
Additional Short Questions
1. What is the role of PostgreSQL in relational database management?
2. Explain the difference between INTEGER and BIGINT data types.
3. How do you add a NOT NULL constraint while creating a table in PostgreSQL?
4. What is the difference between INNER JOIN and OUTER JOIN?
5. What does the ABS() function do in PostgreSQL?
6. Write a query to select the top 5 highest salaries from an employee table.
7. What is the purpose of the CONCAT() function? Provide an example.
8. Write a query to count the total number of records in a student table.
9. Explain the significance of the WITH clause in Common Table Expressions (CTEs).
10. How can you delete all records from a table but keep the table structure intact?
Additional Long Questions
1. Explain the concept of data integrity in SQL. How do PRIMARY KEY and FOREIGN
KEY constraints help in maintaining data integrity?
2. Discuss the advantages of using PostgreSQL over other RDBMS platforms. Provide
examples to support your answer.
3. Explain the differences between TRUNCATE, DELETE, and DROP commands with
suitable examples.
4. Write a query to create a table named students with the following fields: student_id, name,
age, class, and marks. Include appropriate data types and constraints.
5. Discuss the ACID properties in SQL. How does PostgreSQL ensure compliance with these
properties?
6. Explain the concept of transaction management in PostgreSQL with an example of
BEGIN, COMMIT, and ROLLBACK statements.
7. Describe the various types of joins in SQL. Write queries for each type using suitable
examples.
8. Write a query to calculate the average salary from an employee table and display the
names of employees earning above the average salary.
9. Explain the significance of the LIMIT and OFFSET clauses in SQL. Provide examples
showing how to use them to paginate results.
10. Discuss the different types of functions available in PostgreSQL (String, Mathematical,
Date/Time). Provide examples for each type.
Case-Based Questions
1. Case Study on Joins:
Consider two tables:
• Department(dept_id, dept_name)
• Employee(emp_id, emp_name, salary, dept_id)
Write queries to:
• Display employee names and their department names using an INNER JOIN.
• Display all employees and their department names using an OUTER JOIN.
• Display employees without any department assigned using a LEFT JOIN.
2. Case Study on Aggregation:
Consider a table sales(sale_id, product_name, sale_date, amount). Write queries to:
• Find the total sales amount for each product.
• Find the product with the highest total sales.
• Display the top 5 products based on total sales.
3. Case Study on Subqueries:
Consider a table student(student_id, name, age, marks). Write queries to:
• Find the name of the student with the highest marks.
• Display students whose marks are greater than the average marks.
• Find students who have the same marks as the highest marks.
True/False Questions
1. SQL was developed by Microsoft in the 1970s. (False)
2. VARCHAR and TEXT are identical data types in PostgreSQL. (False)
3. The SERIAL data type automatically generates a unique number. (True)
4. The ORDER BY clause sorts rows in ascending order by default. (True)
5. The AND operator returns true if at least one condition is true. (False)
6. The DELETE command removes table structure along with data. (False)
7. The LIMIT clause is used to restrict the number of rows returned. (True)
8. The UPPER() function converts a string to lowercase. (False)
9. The WITH clause is used to define a Common Table Expression (CTE). (True)
10. The AVG() function is used to calculate the sum of values. (False)