πŸŽ“ Velnov

πŸ—„οΈ 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.

Key concepts in this topic

DatabasesRDBMSTablesKeysRowsColumnsData typesPrimary keyConstraintsForeign keyRelationshipsDialectsDDLDMLTCLStyleConventionsCommentsSyntaxSchemaDesignNULLThree-valued logicSELECT

Jump to: Easy Β· Medium Β· Hard

Easy questions (9)

Q1. easy

What does SQL stand for?

  1. A Structured Query Language
  2. B Simple Question Language
  3. C Standard Quality Language
  4. 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?

  1. A Data organised into TABLES of rows and columns, which can be linked by keys
  2. B A database stored only in memory
  3. C A collection of text files
  4. 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?

  1. A A single record - one complete entry, such as one customer
  2. B One field of data
  3. C The table name
  4. 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?

  1. A A named field with a fixed data type, holding one attribute for every row
  2. B One customer's data
  3. C A group of tables
  4. 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?

  1. A MySQL, PostgreSQL, SQL Server, Oracle, SQLite
  2. B MongoDB only
  3. C Excel
  4. 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
  1. A No - select and SELECT both work, though uppercase keywords are the convention
  2. B Yes, keywords must be uppercase
  3. C Yes, keywords must be lowercase
  4. 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;
  1. A -- for a single line, /* ... */ for multiple lines
  2. B # only
  3. C // only
  4. 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?

  1. A A semicolon ;
  2. B A full stop .
  3. C A colon :
  4. 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;
  1. A FROM
  2. B SELECT
  3. C WHERE
  4. 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)
);
  1. A A column (or set of columns) that uniquely identifies each row - never NULL, never duplicated
  2. B The first column of a table
  3. C A password for the table
  4. 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)
);
  1. A A column that references the primary key of another table, creating a relationship
  2. B A key from a foreign country
  3. C An encrypted key
  4. 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?

  1. A SQL is the LANGUAGE; MySQL is a database product that implements it
  2. B They are the same thing
  3. C MySQL is newer SQL
  4. 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?

  1. A Data Definition Language - defines STRUCTURE: CREATE, ALTER, DROP
  2. B Data Deletion Language
  3. C Database Design Logic
  4. 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)?

  1. A SELECT, INSERT, UPDATE, DELETE
  2. B CREATE, ALTER, DROP
  3. C GRANT, REVOKE
  4. 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?

  1. A The structure/blueprint of a database - its tables, columns, types and relationships
  2. B The data itself
  3. C A backup copy
  4. 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?

  1. A The absence of a value - 'unknown' or 'not applicable', which is NOT the same as 0 or an empty string
  2. B The number zero
  3. C An empty string
  4. 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?

  1. A A statement that asks the database for data, typically starting with SELECT
  2. B A table
  3. C A database backup
  4. 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?

  1. A The table of rows and columns returned by a query
  2. B A permanent table
  3. C An error message
  4. 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?

  1. A A database is the container; tables are the individual data structures inside it
  2. B They are the same
  3. C A table contains databases
  4. 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)
);
  1. A A primary key made of TWO OR MORE columns combined
  2. B A key that is encrypted
  3. C A key shared by two tables
  4. 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?

  1. A SQL databases use fixed table schemas and relationships; NoSQL stores flexible documents/key-values without a rigid schema
  2. B NoSQL cannot store data
  3. C SQL is always faster
  4. 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?

  1. A A real-world thing you store data about - which usually becomes a table
  2. B A single column
  3. C A query
  4. 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?

  1. A A data structure that speeds up lookups on a column - like the index at the back of a book
  2. B A numbered list of rows
  3. C The primary key
  4. 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?

  1. A SELECT
  2. B UPDATE
  3. C DELETE
  4. 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?

  1. A It is a standard, declarative way to work with structured data, supported by nearly every data tool
  2. B It is the only programming language
  3. C It is required by browsers
  4. 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

Hard questions (5)

Q18. hard

What does it mean that SQL is a DECLARATIVE language?

  1. A You describe WHAT data you want; the database decides HOW to fetch it efficiently
  2. B You must declare every variable
  3. C It runs line by line like Python
  4. D It only works with declarations

Answer: A β€” You describe WHAT data you want; the database decides HOW to fetch it efficiently

You never write loops over rows. The query optimiser chooses the execution plan - which indexes to use and which join order - based on statistics about your data.

DeclarativeQuery optimiser

Q21. hard

What is referential integrity?

  1. A The guarantee that foreign key values always point to rows that actually exist
  2. B That all data is encrypted
  3. C That tables have the same number of rows
  4. D That queries run fast

Answer: A β€” The guarantee that foreign key values always point to rows that actually exist

The database refuses to insert an order for a non-existent customer, and blocks (or cascades) deletion of a customer with existing orders - preventing 'orphan' records.

Foreign keysIntegrity

Q25. hard

What is a one-to-many relationship?

  1. A One row in table A relates to many rows in table B - e.g. one customer has many orders
  2. B Two tables with equal rows
  3. C Two primary keys
  4. D A table with one column

Answer: A β€” One row in table A relates to many rows in table B - e.g. one customer has many orders

It is implemented by putting the foreign key on the MANY side: orders.customer_id references customers.id. It is the most common relationship type.

RelationshipsForeign keys

Q26. hard

How is a many-to-many relationship implemented?

  1. A With a third JUNCTION table holding foreign keys to both sides
  2. B By adding two primary keys to one table
  3. C It is impossible in SQL
  4. D With a single foreign key

Answer: A β€” With a third JUNCTION table holding foreign keys to both sides

Students take many courses and courses have many students, so an enrollments table links them. Junction tables often carry extra data such as enrolment_date or grade.

Junction tableMany-to-many

Q29. hard

What does ACID stand for in database transactions?

  1. A Atomicity, Consistency, Isolation, Durability
  2. B Accuracy, Control, Integrity, Design
  3. C Access, Create, Insert, Delete
  4. D Automatic Column Index Definition

Answer: A β€” Atomicity, Consistency, Isolation, Durability

These properties guarantee reliable transactions: all-or-nothing (atomicity), valid state (consistency), no interference between concurrent transactions (isolation), and permanence after commit (durability).

ACIDTransactions

Practice β€œIntroduction to Databases & SQL” as a quiz