WorksheetsDatabase & PostgreSQL Quiz
Total questions: 30
Worksheet time: 15mins
Which of the following is used to manage and interact with a database?
Excel
Browser
DBMS
HTTP
Which of the following is an example of an RDBMS?
MongoDB
PostgreSQL
Notepad
JSON
Which command is used to create a new database in PostgreSQL?
NEW DATABASE test;
MAKE DATABASE test;
CREATE DATABASE test;
ADD DATABASE test;
What is the default port number for PostgreSQL?
3306
5432
1521
8080
You cannot drop a database while:
Connected to it
It has no tables
It is empty
It is default
Which data type is most suitable for storing Aadhar numbers?
INT
VARCHAR(10)
BIGINT
TEXT
What does the NOT NULL constraint do?
Prevents duplicate values
Prevents null values
Sets default values
Creates a foreign key
Which constraint ensures all values in a column are unique and not null?
FOREIGN KEY
DEFAULT
PRIMARY KEY
CHECK
Which of the following defines a valid decimal type for storing values like 99.99?
DECIMAL(5,2)
DECIMAL(2,5)
INTEGER
VARCHAR(10)
Which constraint automatically fills a column with a value when none is provided?
PRIMARY KEY
CHECK
DEFAULT
UNIQUE
What does the CHECK constraint do?
Makes the column unique
Checks for nulls
Restricts values based on a condition
Prevents deletion
Which of the following is a correct way to create a column with a default value?
bloodgroup VARCHAR(5) DEFAULT 'O+'
bloodgroup = DEFAULT O+
bloodgroup TEXT PRIMARY 'O+'
bloodgroup NOT NULL 'O+'
Which SQL statement is used to insert data into a table?
ADD INTO
INSERT INTO
PUT INTO
APPEND
Which of the following inserts 3 rows into a table correctly?
One INSERT per row
Use FOR loop
INSERT INTO table VALUES (...), (...), (...);
INSERT EACH INTO table;
What does the UPDATE statement do?
Deletes data
Retrieves data
Changes existing data
Creates a table
What will the following query do? DELETE FROM students;
Delete selected rows
Delete all rows
Delete the table
Nothing
To change a student's marks where name is 'Ahmed', which query is correct?
UPDATE student SET marks = 90 WHERE name = 'Ahmed';
CHANGE marks TO 90 WHERE name = 'Ahmed';
SET marks = 90 FROM student WHERE name = 'Ahmed';
MODIFY student SET marks = 90;
How do you switch to another database in psql?
USE database_name;
CONNECT database_name;
\c database_name
cd database_name
Which operator retrieves values in a given range (inclusive)?
IN
BETWEEN
LIKE
ANY
What does this query return? SELECT * FROM employee WHERE dept IN ('HR', 'IT');
Employees from any department
Only HR employees
HR and IT employees
Exclude HR and IT
Which query finds names starting with 'A'?
fname LIKE '%A'
fname LIKE 'A%'
fname = 'A%'
fname IN 'A%'
What does this do? SELECT * FROM students WHERE marks BETWEEN 70 AND 90;
Returns students with marks above 90
Returns students with marks exactly 70 or 90 only
Returns students with marks 70 to 90
Gives error
To fetch all patients whose name ends with 'a', use:
name LIKE 'a%'
name LIKE '%a'
name = 'a'
name LIKE 'a'
Which query filters rows with age not in 18, 21, 25?
WHERE age NOT IN (18, 21, 25)
WHERE age IN (18, 21, 25)
WHERE NOT age = (18, 21, 25)
WHERE age EXCEPT (18, 21, 25)
Which function returns the total number of rows?
SUM()
MAX()
COUNT()
AVG()
Which function calculates the average of a column?
TOTAL()
AVG()
MEAN()
MEDIAN()
What does this query return? SELECT MIN(salary) FROM employee;
Highest salary
All salaries
Minimum salary
Total salaries
Which query returns the total salary per department?
SELECT dept, salary FROM employee;
SELECT dept, SUM(salary) FROM employee GROUP BY dept;
GROUP BY dept FROM employee;
SELECT SUM(salary) GROUP dept FROM employee;
GROUP BY clause is used to:
Sort results
Combine tables
Group rows with same value
Filter duplicate rows
Which function returns the highest value in a column?
MAX()
MIN()
COUNT()
TOP()
