CS 204 Flashcards
A _______________ consists of tables that are linked together in some meaningful way.
relational database
________________ are created using primary and foreign keys.
Relationships
A _____________ is a minimal set of attributes whose values uniquely identify a record in a table.
primary key
A _______________ is an attribute whose values are the same as the primary key of another table.
foreign key
Relationships are characterized by their ________________: how many records in one table are related to how many records another table.
cardinality
What are the four types of cardinality?
one-to-one
one-to-many
many-to-one
many-to-many
__________________ are software programs that allow users to access and maintain databases.
Database applications
A database __________ is a blueprint of a relational database.
schema
What type of schema displays the hardware, servers, and connections that need to be set up to install the database?
physical schema
What type of schema is the layout and design of the data and tables in the database?
logical schema
What is it called to reduce the redundant data among the tables?
normalizing
How to put a table into 1NF?
Break up the columns with duplication into two or more pieces that reduce duplication.
1NF rules:
Columns must have single values
Columns must have unique names
Values of a given attribute must be of the same data type
No two records (or rows) can be identical
2NF rules:
Table is in 1NF
There are no partial dependencies of any column on the primary key
3NF rules:
The table should be in the 2NF
All non-primary fields are dependent on the primary field
Transitive dependencies are removed
What is a a set of SQL statements that work on the database as a whole, rather than an individual table or row?
Data Definition Language
Common DDL statements:
CREATE (generates a new table)
ALTER (alters table)
DROP (removes a table from the database)
What is a set of SQL statements that act on the data within a table. Select, insert, update, and delete are elements of this language?
data manipulation language
What is a set of SQL statements that control privileges to the data in the database?
Data control language
Grant and revoke are elements of this language.
It’s used by database administrators.
___________ make pictures of tables.
Views
____________ create a sort order on a column
indexes.
M. Mm
An automatic operation to set to a certain event:
trigger
Data definition language (DDL) includes statements that modify the _____ of a database.
structure
The _____ command is used to completely remove a table from the database.
DROP
To build a new table from scratch, use the _____ command.
CREATE
The _____ command is used to modify columns in a table
ALTER
______________ allow database managers to pinpoint specific records within a database without fear of confusing those entries with similar data found elsewhere in a category.
Primary keys
A ______________ is a field that directly identifies another table.
foreign key
What is a template in SQL?
schema
Database schemas depend on _____ and _____.
Database Type, Intended Use
What data type lets you put in a specific amount of characters into a record entry, with no exceptions made for more or fewer characters than the number specified for in the parentheses?
CHAR
______________ lets you put in any number of characters up to the specified limit.
VARCHAR
permits spaces of up to more than 4 billion while taking up four bytes per entry.
INT
permits blanks that fit up to 65,536 different values while only taking up two bytes per entry.
SMALLINT
two data types in SQL that largely do the same thing in that they permit users to add data that includes decimal points.
NUMERIC and DECIMAL
After declaring each data type, however, you will have to enter values for (p,s), in which the ______ refers to the total number of digits in the number, while ______ refers to the number of spots after the decimal.
p,s
productPrice DECIMAL(6, 2),
1043.33
__________ can hold a value 4 bytes in size, meaning it has 7 digits of precision.
Real data
_____________ can hold 8 bytes, or 15 places after the decimal point.
Float data
______________ is similar to float, except that it allows for much larger numbers.
Double data
What is the number of whole numbers and number of digits shown after the decimal point of a complex number.
Precision
True/false data type, binary, one of two answers only
Boolean
What data type?
HH:MM:SS.[nnnnnnn].
H stands for hour, M stands for minute, S stands for second, and all those ns are for fractions of a second.
TIME
YYYY-MM-DD
year, month, and day. Make sure to use the full four year code.
DATE
provides a record of changes made to a specific record.
TIMESTAMP
__________________, is an SQL object data type, meaning it is a reference or pointer to an object. Typically a ________ is a file, image, video, or other large object
Binary Large Object, BLOB
four BLOB types:
TINYBLOB - 256 bytes
BLOB
MEDIUMBLOB
LONGBLOB - 4 gigabytes
SQL doesn’t refer to the type as a BLOB, but with the statement ________________
varbinary(MAX)
Sometimes it is useful to _____________ data in SQL to make sure that useful data is ending up in the proper column of each record.
constrain
Specifies the fields containing the target data
SELECT
Identifies the specific table or tables containing the fields specified in the SELECT clause
FROM
Identifies the criteria to be matched for inclusion in the results
WHERE *optional
Establishes the sorting requirements for retrieved data
ORDER BY *optional
Aggregate functions
SUM
AVG
GROUP BY
It is possible to provide column position numbers from the resultset in an ORDER BY clause of an SELECT statement instead of providing column names?
True
It is possible to provide a column name that is not a part of the resultset in an ORDER BY clause of a SELECT statement.
True
There is only one way to sort the data retrieved from a database using SQL. Which clause of the SELECT statement allows you to do that?
ORDER BY clause
It is ___________ to provide the ASC keyword as SQL assumes an ascending order sort to be the default order but you must specify the DESC keyword for those columns that you want to be sorted in a descending order.
optional
How many columns can be used to sort the data in an ORDER BY clause?
One or more columns, with each one in either ASC or DESC order
_________________ are simply sub-programs, which are commonly used and re-used throughout SQL database applications for processing or manipulating data.
SQL functions
Consider that your database tables have fields with extra spaces and padding in them. Which function should you use to ensure that these extras are not interfering with your queries?
TRIM
Which SQL function can be used when you want to get results on how many days have passed after the dates in the field, such as in a billing cycle?
DATEDIFF
In what scenario would you want to use the UPPER function in SQL?
The text values might be mixed-case, and you want them all in upper case
What do the 6 and 4 represent?
SELECT MID(userName, 6, 4) FROM users;
the 6 represents the number of characters from the beginning of the string to the starting point of the middle selection
4 represents the number of characters selected
_________ is a substitution function; that is, it is used to display one value if another value is NULL.
NVL
NVL is available only in _________, not in MySQL or SQL Server
oracle
NVL can be used with the following data types:
String or Numeric
In order to ensure a NULL inside a numeric field is replaced with a string, you use the _____ keyword
TO_CHAR
NVL is a function used for _____
substitution
correctly display 99999 for NULL Zip Codes in the Customer_Contact table?
SELECT NVL(ZipCode, 99999) FROM Customer_Contact;
The _________ statement is like a menu. Based on the value of a given field, certain instructions are carried out
CASE
In the CASE statement, we use ________ and ________ to determine when and where to branch; always use an _________ to catch any exceptions
WHEN, THEN, ELSE
The ELSE clause in a CASE statement is _____
highly recommended
Required parts of the CASE statement are:
WHEN, THEN, and END required, ELSE not required but recommended
________ function will give the totals of a field,
________ will give the average value,
_________ will count the number of occurrences and
_________________ will give the maximum and the minimum values of the given fields respectively.
SUM
AVG
COUNT
MAX and MIN
key DML commands in SQL
SELECT
INSERT
UPDATE
DELETE
What is created or destroyed using DML?
the data itself
The changes made by the DML statements are managed by a group of commands known as ______________
TCL transaction control language
The ____________ command is used to permanently save any transaction into the database.
COMMIT
INSERT INTO Lessons VALUES('LS004', 'Service Engineering'); COMMIT;
The ______________ command is used to temporarily save a transaction so that you can roll back to that point whenever necessary.
SAVEPOINT
The _______________ command restores the database to the last committed state. It is also used with the SAVEPOINT command to jump to a SAVEPOINT in a transaction.
ROLLBACK
Which command allows us to select a part of a string that starts from the beginning?
LEFT
LEFT is a useful statement when:
The text is limited in size
What function will return the length of the string?
LEN()
Which statement will show part of a string, starting from the right-most character?
RIGHT
Which statement will show a portion of a string, starting from a specific position?
SUBSTR()
If you want to get all records from two tables that are related, you can use a ___________
inner join
A ______________ returns ALL matching records in the left-hand table, plus the records that match in the middle (the inner join).
left outer join
A ______________ returns ALL matching records in the right-hand table, plus the records that match in the middle (the inner join).
right outer join
A _________________ returns results from both tables.
full outer join
A ____________ is similar to a full outer join, except that a _____________ returns all of the records into new rows.
union
Consider the following tables of data: Location and Purchases. We want to retrieve all purchases AND all locations, even if there were no purchases made at those locations. What type of SQL join is appropriate?
left-outer join
A left outer join will return not only purchases at all locations but locations that did not have a purchase.