SQL Basics for Beginners
- 53Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is data, and how can it help people or organizations make decisions?
53 questions
- 1
What is data, and how can it help people or organizations make decisions?
Model answer
Data is information or facts about something. Extracting meaning from data can support informed decisions.
Explanation
Data consists of facts or attributes about something. Analyzing it can reveal useful information for decisions.
- 2
Give examples of customer data and explain how a business might use them.
Model answer
Customer data can include age, income, and buying habits. Businesses can use these attributes to make better decisions about products and services.
Explanation
Customer attributes such as age, income, and buying habits can help a business choose products or services and improve profits or efficiency.
- 3
What is a database, and what is its basic purpose?
Model answer
A database is a dedicated location for storing data so it can be managed, changed, processed, and analyzed.
Explanation
A database provides a dedicated place to store data so it can be worked with and analyzed.
- 4
Describe several ways databases help organizations work with data.
Model answer
Databases store and manage large amounts of data, support updates and analysis, and help keep data secure.
Explanation
Databases help organize and manage large quantities of data, protect it, and make it useful for analysis and decisions.
- 5
What is SQL, and what kinds of actions does it let users perform on database data?
Model answer
SQL is a query language used to communicate with databases, retrieve data, and perform actions such as modifying or deleting data.
Explanation
SQL is described as a query language for communicating with databases and retrieving or changing data.
- 6
Explain how a SQL query produces a result, using
SELECT name FROM customersas an example.Model answer
A user writes and submits a SQL query; the database processes it and returns the requested output.
SELECT name FROM customersreturns customer names.Explanation
A query is sent to the database system, which processes it and returns a result. In the example, the result contains customer names.
- 7
Why is SQL useful in business intelligence work?
Model answer
SQL is widely used because it provides an effective way to retrieve and manipulate data, including in business intelligence tools.
Explanation
SQL is widely used to query and manipulate data and is common in business intelligence tools, which depend on working with data.
- 8
What is a table in a relational database?
Model answer
A table is a structured collection of data arranged in rows and columns.
Explanation
A table organizes a set of data into records and attributes, with columns describing the records.
- 9
Distinguish between a row and a column in a database table.
Model answer
A row is a record, and a column is an attribute describing the records, such as name, age, or phone number.
Explanation
Rows represent records, while columns represent attributes that describe those records, such as a customer's name or age.
- 10
What does the term field refer to, and how does it relate to a column?
Model answer
A field is a location for storing an attribute value, while a column represents an attribute of the records in a table.
Explanation
A field is the location in which an attribute's value is stored; the table's columns define the attributes.
- 11
What does it mean for a table to have a consistent set of typed attributes?
Model answer
A table uses a consistent set of columns, and each column has a defined data type for the values it stores.
Explanation
The content describes tables as having a consistent set and number of typed attributes, represented by their columns.
- 12
What is the difference between a NULL value and a NOT NULL requirement?
Model answer
NULL indicates that a value is absent or unknown. A NOT NULL constraint prevents a record from omitting a value in that column.
Explanation
A NULL value represents an absent or unknown value, whereas NOT NULL requires the column to contain a value.
- 13
What is a primary key, and why must its value be unique?
Model answer
A primary key is a column or set of columns that uniquely identifies each row; its value cannot be duplicated.
Explanation
A primary key uniquely identifies each record, so it must not be duplicated. An ID is a common choice.
- 14
Why might an ID be a better record identifier than a person's name?
Model answer
An ID primary key gives each record a unique identifier, making it easier to locate a row even when other values, such as names, are repeated.
Explanation
Using a primary key such as an ID makes it possible to find a specific row without relying on potentially repeated details such as names.
- 15
What is a database constraint, and what does it control?
Model answer
A constraint is a rule that limits or controls the data allowed in a table.
Explanation
Constraints specify rules that restrict which values or records may be entered into a table.
- 16
What do the column types
INTandVARCHAR(30)indicate?Model answer
INTspecifies an integer value, whileVARCHAR(30)specifies variable-length text with a limit of 30 characters.Explanation
In the example,
INTis used for integer values, whileVARCHAR(30)is used for text with a declared maximum length of 30 characters. - 17
Why might a database store customer details and product details in separate tables?
Model answer
Related information can be divided between tables—for example, customer details in one table and product details in another—and connected through a relationship.
Explanation
The customer and product information can be stored in separate tables, with a relationship connecting them.
- 18
How does a child table use the primary key of its parent table?
Model answer
The parent table's primary key is stored in a column of the child table, allowing records in the two tables to be related.
Explanation
In a parent-child relationship, the parent table's primary key is included as a column in the child table to link related records.
- 19
What is a foreign key, and how does it connect tables?
Model answer
A foreign key is a column in one table that refers to a key—typically the primary key—in another table.
Explanation
A foreign key in the child table refers to a key in the parent table, linking the tables.
- 20
How could a product-model table refer to the customer associated with a product?
Model answer
A product-model table can store a
customer_idforeign key that references the corresponding customer'sid.Explanation
The example links a product-model row to a customer using the product-model table's
customer_idforeign key referencing the customer table'sid. - 21
What does ordinality describe, and how does the content represent optional versus required relationships?
Model answer
Ordinality indicates whether a relationship is optional or required; the content represents optionality with zero and a required relationship with a perpendicular line.
Explanation
Ordinality indicates whether a relationship is optional or required from the parent-to-child perspective. The described notation uses zero for optional and a perpendicular line for required.
- 22
Using the book example, contrast an optional relationship with a required relationship.
Model answer
A book may have no associated owner, making that relationship optional, but it must have an author, so the author relationship is required.
Explanation
The book example distinguishes a book that may have no owner from a book that must have been written by someone.
- 23
What does cardinality describe, and what are three possible relationship types?
Model answer
Cardinality describes how many records in one table can relate to records in another, such as one-to-one, one-to-many, or many-to-many.
Explanation
Cardinality describes the number of related records possible between parent and child tables; examples include one-to-one, one-to-many, and many-to-many.
- 24
What integrity rule does a foreign key enforce, and what behavior does
ON DELETE CASCADEspecify?Model answer
A foreign key can require a referenced customer to exist before a related product-model row is added. With
ON DELETE CASCADE, deleting the referenced parent can cascade to related child rows.Explanation
A foreign-key constraint can prevent adding a child row whose referenced customer does not exist. The described
ON DELETE CASCADErule also specifies cascading behavior when a referenced parent row is deleted. - 25
What is DDL used for, and which commands are examples of DDL in the content?
Model answer
Data definition language (DDL) commands define or change database structures; examples include
CREATE,DROP,TRUNCATE,ALTER, andCOMMENT.Explanation
DDL commands define or change database structures. The examples include creating, dropping, truncating, altering, and adding comments to data-dictionary information.
- 26
Compare the purposes of
CREATEandDROP.Model answer
CREATEcreates a database or table.DROPremoves the database or table structure.Explanation
CREATEmakes a database or table, whileDROPremoves the database or table itself. - 27
How does
TRUNCATEdiffer fromDROPwhen applied to a table?Model answer
TRUNCATEremoves all records but keeps the table structure;DROPremoves the table itself.Explanation
TRUNCATEremoves the table's records while retaining the table itself, whereasDROPremoves the table. - 28
What are
ALTERandCOMMENTused for in the command overview?Model answer
ALTERchanges a table or its structure, whileCOMMENTadds comments to data-dictionary information.Explanation
ALTERis used to change a table or its structure.COMMENTis described as adding comments to a data dictionary. - 29
What does the
USEcommand do when a server contains multiple databases?Model answer
USEselects the database that subsequent work will use.Explanation
The
USEcommand selects a database to work in when several databases are available. - 30
Compare the purposes of
INSERT INTOandUPDATE.Model answer
INSERT INTOadds rows to a table.UPDATEchanges values in existing rows.Explanation
INSERT INTOadds values to a specified table, whileUPDATEchanges existing values in selected records. - 31
How can
DELETEbe used to remove a particular row without deleting every row?Model answer
DELETEremoves records from a table, and a condition can be used to target particular rows rather than all rows.Explanation
DELETEremoves selected records from a table; the content contrasts deleting a particular row with removing every row. - 32
What is the difference between
GRANTandREVOKE?Model answer
GRANTgives users access privileges;REVOKEwithdraws previously granted privileges.Explanation
GRANTgives users database privileges, whileREVOKEwithdraws privileges that have been granted. - 33
Compare
COMMITandROLLBACKin transaction control.Model answer
COMMITsaves transaction changes.ROLLBACKundoes uncommitted changes, returning to the prior committed state.Explanation
COMMITsaves transaction changes, whileROLLBACKundoes changes and returns to the previous committed state in the described example. - 34
What purposes do
SAVEPOINTandSET TRANSACTIONserve?Model answer
SAVEPOINTmarks a point within a transaction, whileSET TRANSACTIONspecifies characteristics for the transaction.Explanation
A savepoint marks a position within a transaction, and
SET TRANSACTIONspecifies transaction characteristics. - 35
What does CRUD stand for, and what kinds of operations does it describe?
Model answer
CRUD stands for Create, Read, Update, and Delete—the basic operations for working with data.
Explanation
CRUD names the four basic kinds of data operation: creating, reading, updating, and deleting.
- 36
What does
SELECTdo, and what does the*symbol request in a select list?Model answer
SELECTretrieves data from a table, andSELECT *requests all columns.Explanation
The content presents
SELECTas the command for querying data from a table; selecting*requests all columns. - 37
How would you retrieve only the name and age columns from a customer table?
Model answer
List the desired column names after
SELECT, separated by commas, to return only those columns.Explanation
Naming particular columns in the select list returns only those columns instead of every column in the table.
- 38
What is the purpose of a
WHEREclause in a query?Model answer
A
WHEREclause specifies a condition that filters which rows are returned.Explanation
A
WHEREclause filters rows according to a condition, allowing a query to target particular records such as customers from one city. - 39
How can
ANDbe used to find customers who match two conditions at once?Model answer
ANDcombines conditions so that a row is returned only when both conditions are satisfied.Explanation
The
ANDoperator requires both conditions to be true, such as matching a city and a product in the same row. - 40
How does
ORDER BYwork, and how do you request descending order?Model answer
ORDER BYsorts rows by a chosen column. The default is ascending order;DESCspecifies descending order.Explanation
ORDER BYsorts the returned rows using a chosen column. The content says ascending order is the default when direction is omitted, andDESCrequests descending order. - 41
What does each of
SUM,AVG,MAX, andMINcalculate?Model answer
SUMtotals values,AVGcalculates their average,MAXreturns the largest value, andMINreturns the smallest.Explanation
Aggregate functions calculate a result across values in a column. The examples use
SUMfor a total,AVGfor an average, andMAXorMINfor an extreme value. - 42
How can a query calculate the total income only for customers who bought a particular product?
Model answer
Add a
WHEREcondition to restrict which rows an aggregate uses, such as summing income only for rows where the product is a phone.Explanation
An aggregate query can use
WHEREto restrict the rows considered; for example, summing income only for customers who bought a phone. - 43
What does
COUNTcount, and why does the choice of column matter?Model answer
COUNTcounts values in a column; because NULL values may be excluded, use a column that is non-NULL when counting records.Explanation
COUNTcounts values in the specified column. The content cautions that NULL values may not be counted, so a column that is guaranteed to have a value is preferable when counting records. - 44
How does
DISTINCTchange the results of a query on customer names?Model answer
DISTINCTreturns unique values and removes duplicates from the query result.Explanation
DISTINCTremoves repeated values from the result, so a customer name appearing in multiple rows is returned once. - 45
How can an update avoid changing every row in a table?
Model answer
Use a
WHEREclause with conditions that identify the intended row, then useUPDATE ... SETto change the required columns.Explanation
A condition on a row's attributes can identify the intended record for an update; the example uses both the customer's name and product to target one row.
- 46
How do
SELECT,FROM, and a table-qualified column name work together in a query?Model answer
Name the desired columns after
SELECTand their source table afterFROM; qualify a column with its table name when needed.Explanation
The
SELECTlist names the columns to return, whileFROMidentifies their source table. When querying multiple tables, prefixes such ascustomer.namespecify which table a column belongs to. - 47
Why would you use a join between customer and product tables?
Model answer
A join combines rows from related tables so one query can retrieve fields from both tables.
Explanation
A join combines related rows from different tables, enabling a query to return customer details alongside product details.
- 48
Which columns should be matched to join a customer table to a product-model table when the latter has a customer foreign key?
Model answer
Match
customer.idwithproduct_model.customer_idto link each product-model row to its customer.Explanation
The foreign-key relationship supplies the matching values for a join: the customer table's ID is matched to the product-model table's customer ID.
- 49
How does an auto-incrementing ID simplify inserting new records?
Model answer
An auto-incrementing integer ID can serve as a primary key, with the database assigning a new ID as each row is added.
Explanation
The customer table example uses an integer ID as a primary key and applies auto-increment so the database assigns successive IDs as rows are inserted.
- 50
How should a table's nullability rules reflect whether a field is required or may be unknown?
Model answer
Use
NOT NULLfor required values such as an ID or name; leave a column nullable when its value may be unavailable.Explanation
The example uses
NOT NULLfor required fields, such as an ID or name, and allows a potentially unavailable field such as income to be left nullable. - 51
When inserting values, how should text values be distinguished from numeric values?
Model answer
Enclose text values in quotation marks when inserting them; enter numeric values as numbers.
Explanation
A SQL string value in an insert statement is enclosed in quotation marks, while the example enters numeric values without quotes.
- 52
What role does a semicolon play at the end of a SQL statement in the demonstration?
Model answer
A semicolon marks the end of a SQL statement in the demonstrated MySQL workflow.
Explanation
The demonstration uses a semicolon to mark the end of a SQL statement, allowing the database client to recognize that the query is complete.
- 53
What is the basic sequence for creating and then working in a new database?
Model answer
Create the database, select it with
USE, and then create the required tables inside it.Explanation
The example creates a database, selects it with
USE, and then creates tables inside it, showing the order of these basic setup steps.

Ask anything
We've read this whole study set, so questions about it get the best answers.