Terms To Remember Flashcards
What is a row called in a database?
A Record
What is a column called in a database?
Field
Databases: what function do they provide?
They organize the information we receive so that we can use it
Tables
A collection of rows and columns. A database can contain more than one table.
The structure of tables in the database?
Schema. The database’s schema includes the information about the layout of tables and other information about the database itself.
Relational Database
Tables are made up of rows and columns. Columns are the relation.
What are common column data types?
Number, text, date, true/false value, binary data
Composite Key
Two or more fields taken together to act as a unique identifier
Foreign Key
Primary key from one table when referencing another table
What are the three types of Database Relationships?
One-to-many
Many-to-many
One-to-one
Transaction
A set of operations that all must be completed
What does ACID stand for in relation to transactions?
Atomic
Consistent
Isolated
Durable
What does Atomic mean?
Means that the transaction is indivisible, that pieces of it can’t be separated out.
What does consistent mean?
Whatever the transaction does, it needs to leave the database in a valid or consistent state. Can’t violate integrity.
What does Isolated mean?
While the activities in the transaction are being completed, nothing else can make changes to the data involved
What does Durable mean?
Information actually gets written to the database.
SQL
Structured Query Language
What does SQL do?
Allows statements to be written for DBMS to interpret how to interact with data (DML)
Offers feature to manage the database itself, such as creating or modifying tables and controlling access to tables. (DDL and DCL)
What does CRUD stand for?
Create
Read
Update
Delete
A relationship connects two pieces of data in different _____ in the same _____.
tables; database
Which is a good example of a candidate key?
an employee ID number. Any piece of data that uniquely represents a row is a candidate key, and if you have a value that occurs in the data naturally, that’s a natural key.
How many SQL clauses are in this query?
SELECT Width,Height FROM Shapes;
two. Each keyword, SELECT and FROM, defines a single clause.
In a database, what is a relation?
a set of attributes (columns) that describe information about specific instances (rows) of an entity
This was the correct answer
When is an associative table useful?
when records need to be related in a many-to-many relationship. An associative (or linking) table relates foreign keys from different tables to associate their records.
What does the term transaction mean?
A transaction is a collection of steps that must all be completed in order for a change to be made to the database.
If you reference a key from Table A in Table B, what is that value in Table B?
a foreign key. Because it refers to a key in another table, in this context, the value is called a foreign key.
In a database where you keep track of records for a school, what tables should you expect to find?
Each of these tables holds a different kind of information, and because the tables can store more than one record, the table names are pluralized.
When talking about data types, what do you call the group of types that represent text?
string types. There are various kinds of string types to accommodate text of different lengths.
To store the value 4:32PM, December 27, 2019, which data type would you use?
DATETIME. This is the correct type, because it includes both a date component and a time component. The other options here do not.
Which condition represents a NULL value?
a date cell containing no data. A cell, regardless of its data type, is NULL when it has no value.
If you don’t use a number type to store numeric data, _____.
you need to take additional steps to process the data as a number whenever you use it. Storing numeric data in numeric data types gives you the ability to work with numbers directly, as you might do when you use mathematical operations in queries.
When planning a database, what do you start with?
an Entity Relationship (ER) diagram. Using an ER diagram, you can plan out what fields will appear on which tables, and how they’re related.
Three Relationships?
one to one
one to many
many to many
Referential Integrity
Databases are aware of relationships and won’t allow a user to modify data in a way that violates those relationships.
Which is an example of referential integrity?
preventing the user from entering a record that refers to nonexistent data
Defining relationships helps you to do what?
reduce the repetition of data across tables
model real-world scenarios and requirements
understand how your data should be stored
What is it called if you delete a record and the database goes on and deletes other records associated with that record?
a cascading delete
In a one-to-many relationship, the value representing the ‘many’ side is what?
foreign key
When modeling a many-to-many relationship, how should you name the linking table?
with a combination of the names of the tables it’s linking
When you need to create a many-to-many relationship, what do you need to generate?
a linking table that has a one-to-many relationship with two or more tables
Which scenario represents a one-to-many relationship?
bank customers linked to their bank accounts. A certain customer can have multiple accounts, but a certain account can belong to only one customer.
A one-to-one relationship _____.
allows only one record to be connected to only one other record
First Normal Form (1NF) Normalization Rule?
Values in each cell should be atomic and tables should have no repeating groups.
Second Normal Form (2NF) Normalization Rule?
No value in a table should depend on only part of a key that can be used to unique identify a row
Third Normal Form (3NF) Normalization Rule?
Values should not be stored if they can be calculated from another non-key field
Denormalization
The process of intentionally duplicating information in a table, in violation of normalization rules
If you can figure out the value of one non-key field in a row by looking at another non-key field in that same row, what do you violate?
Third Normal Form
In order to put a database into Third Normal Form, _____.
it must also be in First and Second Normal Form
First Normal Form tells you to do what?
remove repeating groups
When might you choose to denormalize a table?
Retrieving the data upon request would be slow or burdensome, and you are able to pre-calculate or store a copy of the data somewhere it can be retrieved faster.
A table has two rows with the same values in all columns. Which step can you take to have this table meet the first normal form (1NF) requirements?
Add a primary key to the table. The primary key will add a unique value for each row, and thus eliminate the repeating duplicate rows issue.
What is the foreign key in the table created after this command?
CREATE TABLE Models (
ModelID INT(6) NOT NULL AUTO_INCREMENT,
Color INT(6) REFERENCES Colors(ColorID),
PRIMARY KEY(ModelID)
);
Color
Which SQL command will you use to create a new database called “mydb”?
CREATE DATABASE mydb;
Which of these is not an example of a time when you would use an aggregate function?
looking up customers with the name Rafael Montresso. Aggregate functions are used to tell you about certain characteristics of multiple records. Requesting a record by specific field values is not an aggregate operation.
Which WHERE condition can you use to find all records containing a first name starting with the letter “A”?
WHERE FirstName LIKE “A%”;
When using an aggregate function, how many results do you expect?
Aggregate functions return one value that describes a set of data.
What should come instead of the ??? placeholder for this query to return all fields and records in the table?
SELECT ??? FROM mytable;
*
The asterisk is used as a wildcard to retrieve everything from the given table.
True or False? In any given query, you can only join together a maximum of two tables.
FALSE. You can join together many tables as long as you tell the database which pairs of values on the tables are intended to match.
In order to use records from more than one table in a query, you need to _____ the tables based on some matching criteria.
join
Joining tables allows you to match rows from one table with rows on another table.
If a table is set to auto-increment the primary key, you’ll need to know the next value and set it manually when you enter a record. True or false?
FALSE.
When the database automatically increments a key field, you don’t need to worry about setting the value. The database will provide the next value in the sequence automatically.
When modifying a record, it’s a good idea to specify the record _____.
as precisely as possible, ideally using the primary key
True or false? In order to sort results based on a field, that field needs to appear in the final output.
FALSE
A field used for sorting doesn’t need to appear in the ‘SELECT’ clause of the query.
A SQL statement that returns requested records from the database is called:
a SQL query
Where can you write SQL?
in database management software
in an app’s source code
at a command-line console
You can narrow down the results that a query returns by only asking for results where a _____ matches a given value.
field
Which of these tasks can you accomplish using SQL as a DML?
inserting a record into a table
When first defining a table, what should you specify?
A. the table’s name
C. the fields and type of data they contain
E. the primary key and any referential constraints
Which sorting option shows dates from latest to earliest?
ORDER BY Date
DESC
When you use SQL statements to create or modify the structure of a database, what is SQL being used as?
a Data Definition Language (DDL)
As a Data Definition Language, SQL can be used to create and modify the structure of database tables.
What is the correct SQL syntax to use when joining tables A and B on their “ID” field?
SELECT * FROM A
JOIN B ON A.ID=B.ID
When telling the database that a certain field must not contain an empty value, you say that it is:
not null
For a table that holds the purchase amounts in a grocery store over time, which query will likely return the highest value?
SELECT SUM(amount) FROM purchases;
What is the possible issue with this query?
UPDATE mytable SET price=5;
It may update undesired records.
Without a WHERE condition, this query will update all records including possibly undesired ones.
Which database is often used in a big data context?
Hadoop and Spark are often used for big data applications.
Microsoft Access is generally considered a(n) _____ database platform.
desktop
Desktop databases are typically hosted on a workstation rather than a dedicated server, and they’re designed to support a few to a few hundred users.
Relational databases can store all of these except what?
graph data
Some NoSQL databases are designed to store data arranged as graphs rather than in relations.
A stored procedure is _____.
a predefined query or statement
Stored procedures are queries that are stored on the server, and they can be called by developers or users in their queries.
An index _____.
helps to increase the speed of lookups using a particular column at the cost of speed while modifying records
As with denormalization, indexes offer a trade off.
What is it called when a malicious user tries to change the way a SQL statement works by entering their own SQL?
injection
This kind of attack involves someone injecting their own code into an application.
If you store certain kinds of information, your database may be subject to certain compliance regulations. True or false?
TRUE
If you store personally identifiable information (PII), health information, or some other kinds of information, your database may be subject to various regulations. Be sure to do your research and stay in compliance!
What is a database transaction?
a group of statements that runs or fails as a whole
Transactions combine multiple statements into a single logical block, where one failing statement rolls back the entire action.
What is a table?
A table stores and displays data in a structured format consisting of columns and rows that are similar to those seen in Excel spreadsheets.
What does SQL do?
SQL is used to access and manipulate a database.
It can be used to select & filter, add and remove data and tables, and much more.
The SELECT statement
used to select data from a table.
*
selects all columns of the table.
in order to select everything from the Customers table, we use the following:
SELECT * FROM Customers
Instead of *, we can specify a column that we want to select.
For example, let’s select only the City column:
SELECT City FROM Customers
We can specify multiple columns in the SELECT statement by separating them with commas.
For example:
SELECT firstname, lastname FROM Customers
You can run multiple SQL queries, by separating them with semicolons.
For example:
SELECT firstname, lastname
FROM Customers;
SELECT firstname, city, age
FROM Customers;
SQL is case insensitive.
The following statements are equivalent and will produce the same result:
select city from Customers;
SELECT City FROM Customers;
sElEct ciTY From Customers;
Common practice is all upper case
The ORDER BY command
used to sort the data in a SELECT statement.
By default, ORDER BY sorts the results in
ascending order. (A to Z)
We can specify the ordering using the
ASC and DESC keywords.
SELECT * FROM Customers
ORDER BY firstname DESC