ποΈ SQL Β· Topic 1 of 20
Introduction to Databases & SQL β SQL Questions with Answers
30 practice questions on Introduction to Databases & SQL, each with the correct answer and a clear explanation of why it is right. Read through them as revision notes, or take this topic as an interactive quiz to test yourself.
9 easy Β· 16 medium Β· 5 hard Β· Part of SQL: Databases from basics to window functions - 20 topics.
Easy questions (9)
Q1. easy
What does SQL stand for?
- A Structured Query Language
- B Simple Question Language
- C Standard Quality Language
- D Sequential Query Logic
Answer: A β Structured Query Language
SQL is the standard language for storing, retrieving and managing data in relational databases. It is often pronounced 'sequel' or spelled out as S-Q-L.
DatabasesRDBMS
Q2. easy
What is a relational database?
- A Data organised into TABLES of rows and columns, which can be linked by keys
- B A database stored only in memory
- C A collection of text files
- D A spreadsheet program
Answer: A β Data organised into TABLES of rows and columns, which can be linked by keys
Relational databases store data in tables. Relationships between tables are created with keys - for example an Orders table referencing a Customers table.
TablesKeys
Q3. easy
In a table, what does a ROW represent?
- A A single record - one complete entry, such as one customer
- B One field of data
- C The table name
- D A query result only
Answer: A β A single record - one complete entry, such as one customer
A row (also called a record or tuple) is one complete item. A column (field or attribute) is one property shared by every row, such as email.
RowsColumns
Q4. easy
What is a COLUMN in a table?
- A A named field with a fixed data type, holding one attribute for every row
- B One customer's data
- C A group of tables
- D A saved query
Answer: A β A named field with a fixed data type, holding one attribute for every row
Every column has a name and a data type (INT, VARCHAR, DATE...). That type is enforced, so a numeric column cannot accidentally store text.
ColumnsData types
Q7. easy
Which of these is a popular relational database system?
- A MySQL, PostgreSQL, SQL Server, Oracle, SQLite
- B MongoDB only
- C Excel
- D JSON
Answer: A β MySQL, PostgreSQL, SQL Server, Oracle, SQLite
All of those speak SQL with small dialect differences. MongoDB is a NoSQL document database and does not use SQL.
RDBMSDialects
Q11. easy
Is SQL case-sensitive for its KEYWORDS?
SELECT name FROM students; -- conventional
select name from students; -- also valid
- A No - select and SELECT both work, though uppercase keywords are the convention
- B Yes, keywords must be uppercase
- C Yes, keywords must be lowercase
- D Only in MySQL
Answer: A β No - select and SELECT both work, though uppercase keywords are the convention
Keywords are case-insensitive. Writing them in CAPS makes queries easier to read. Note that DATA and table/column names may be case-sensitive depending on the database and operating system.
StyleConventions
Q12. easy
How do you write a comment in SQL?
-- get active users
SELECT * FROM users /* all columns */
WHERE active = 1;
- A -- for a single line, /* ... */ for multiple lines
- B # only
- C // only
- D Comments are not supported
Answer: A β -- for a single line, /* ... */ for multiple lines
Two hyphens start a single-line comment; /* */ wraps a block. (MySQL also accepts # for single lines, but -- is the standard.)
Comments
Q13. easy
What character traditionally ends an SQL statement?
- A A semicolon ;
- B A full stop .
- C A colon :
- D Nothing
Answer: A β A semicolon ;
The semicolon separates statements. Some tools let you omit it for a single query, but it is required when running several statements together.
Syntax
Q23. easy
Which clause specifies WHICH TABLE to read from?
SELECT name, email
FROM customers;
- A FROM
- B SELECT
- C WHERE
- D TABLE
Answer: A β FROM
SELECT lists the columns you want; FROM names the source table. Both are required in a basic query.
SELECTFROM
Medium questions (16)
Q5. medium
What is a PRIMARY KEY?
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(50)
);
- A A column (or set of columns) that uniquely identifies each row - never NULL, never duplicated
- B The first column of a table
- C A password for the table
- D The most important data in a row
Answer: A β A column (or set of columns) that uniquely identifies each row - never NULL, never duplicated
The primary key guarantees every row can be identified unambiguously. Typical choices are an auto-incrementing id or a natural unique value like an ISBN.
Primary keyConstraints
Q6. medium
What is a FOREIGN KEY?
CREATE TABLE orders (
id INT PRIMARY KEY,
customer_id INT,
FOREIGN KEY (customer_id) REFERENCES customers(id)
);
- A A column that references the primary key of another table, creating a relationship
- B A key from a foreign country
- C An encrypted key
- D A backup key
Answer: A β A column that references the primary key of another table, creating a relationship
Foreign keys enforce referential integrity: an order cannot reference a customer_id that does not exist, and the database can block deleting a customer who still has orders.
Foreign keyRelationships
Q8. medium
What is the difference between SQL and MySQL?
- A SQL is the LANGUAGE; MySQL is a database product that implements it
- B They are the same thing
- C MySQL is newer SQL
- D SQL is only for Microsoft
Answer: A β SQL is the LANGUAGE; MySQL is a database product that implements it
You write SQL; MySQL, PostgreSQL and SQL Server are programs that run it. Each adds its own extensions, which is why some syntax differs between them.
DialectsRDBMS
Q9. medium
What does DDL stand for, and what does it do?
- A Data Definition Language - defines STRUCTURE: CREATE, ALTER, DROP
- B Data Deletion Language
- C Database Design Logic
- D Dynamic Data Loader
Answer: A β Data Definition Language - defines STRUCTURE: CREATE, ALTER, DROP
DDL builds and changes the schema itself. DML (Data Manipulation Language) handles the data inside: SELECT, INSERT, UPDATE, DELETE.
DDLDML
Q10. medium
Which statements belong to DML (Data Manipulation Language)?
- A SELECT, INSERT, UPDATE, DELETE
- B CREATE, ALTER, DROP
- C GRANT, REVOKE
- D COMMIT, ROLLBACK
Answer: A β SELECT, INSERT, UPDATE, DELETE
DML works with the rows. DDL changes structure, DCL (GRANT/REVOKE) handles permissions, and TCL (COMMIT/ROLLBACK) manages transactions.
DMLDDLTCL
Q14. medium
What is a SCHEMA?
- A The structure/blueprint of a database - its tables, columns, types and relationships
- B The data itself
- C A backup copy
- D A query result
Answer: A β The structure/blueprint of a database - its tables, columns, types and relationships
The schema describes how data is organised. In some systems (PostgreSQL, SQL Server) a schema is also a named namespace that groups tables, like public.users.
SchemaDesign
Q15. medium
What is a NULL value in SQL?
- A The absence of a value - 'unknown' or 'not applicable', which is NOT the same as 0 or an empty string
- B The number zero
- C An empty string
- D A syntax error
Answer: A β The absence of a value - 'unknown' or 'not applicable', which is NOT the same as 0 or an empty string
NULL means 'no value recorded'. Because it is unknown, comparisons with it behave specially - you must use IS NULL, never = NULL.
NULLThree-valued logic
Q16. medium
What is a QUERY?
- A A statement that asks the database for data, typically starting with SELECT
- B A table
- C A database backup
- D A user account
Answer: A β A statement that asks the database for data, typically starting with SELECT
A query requests data and returns a RESULT SET - itself a table of rows and columns, which is why queries can be nested and combined.
SELECTResult set
Q17. medium
What is a result set?
- A The table of rows and columns returned by a query
- B A permanent table
- C An error message
- D The database log
Answer: A β The table of rows and columns returned by a query
Result sets are temporary. Because they look like tables, they can feed into subqueries, CTEs and views.
QueriesSubqueries
Q19. medium
What is the difference between a database and a table?
- A A database is the container; tables are the individual data structures inside it
- B They are the same
- C A table contains databases
- D A database holds only one table
Answer: A β A database is the container; tables are the individual data structures inside it
One database typically holds many related tables - for a shop: customers, products, orders, order_items.
DatabaseTables
Q20. medium
What is a composite (compound) primary key?
CREATE TABLE enrollments (
student_id INT,
course_id INT,
PRIMARY KEY (student_id, course_id)
);
- A A primary key made of TWO OR MORE columns combined
- B A key that is encrypted
- C A key shared by two tables
- D A backup key
Answer: A β A primary key made of TWO OR MORE columns combined
Common in link tables: in enrollments, neither student_id nor course_id is unique alone, but together they uniquely identify one enrolment.
Composite keyMany-to-many
Q22. medium
What is the difference between SQL and NoSQL databases?
- A SQL databases use fixed table schemas and relationships; NoSQL stores flexible documents/key-values without a rigid schema
- B NoSQL cannot store data
- C SQL is always faster
- D They are identical
Answer: A β SQL databases use fixed table schemas and relationships; NoSQL stores flexible documents/key-values without a rigid schema
Relational databases excel where data is structured and consistency matters (banking, orders). NoSQL suits flexible or rapidly changing data at large scale. Many systems use both.
NoSQLMongoDB
Q24. medium
What is an ENTITY in database design?
- A A real-world thing you store data about - which usually becomes a table
- B A single column
- C A query
- D A user login
Answer: A β A real-world thing you store data about - which usually becomes a table
Entities (Customer, Product, Order) become tables; their attributes become columns; the links between them become foreign keys. This is the basis of ER modelling.
ER modelDesign
Q27. medium
What is an INDEX, in one sentence?
- A A data structure that speeds up lookups on a column - like the index at the back of a book
- B A numbered list of rows
- C The primary key
- D A backup of the table
Answer: A β A data structure that speeds up lookups on a column - like the index at the back of a book
Without an index the database scans every row. With one it jumps straight to matches. The cost is extra storage and slightly slower writes.
IndexesPerformance
Q28. medium
Which statement retrieves data WITHOUT changing it?
- A SELECT
- B UPDATE
- C DELETE
- D INSERT
Answer: A β SELECT
SELECT is read-only, so it is always safe to run. The other three modify data - always test them with a SELECT using the same WHERE clause first.
SELECTSafety
Q30. medium
Why is SQL still essential decades after its creation?
- A It is a standard, declarative way to work with structured data, supported by nearly every data tool
- B It is the only programming language
- C It is required by browsers
- D It replaced Python
Answer: A β It is a standard, declarative way to work with structured data, supported by nearly every data tool
Analytics, reporting, dashboards and machine-learning pipelines all pull from relational stores, so SQL remains one of the most in-demand data skills.
CareersData analysis