Full Study Flashcards
(113 cards)
What are the three main Objects in a Database, with a explanation of what they are?
Entities – Major object that holds significant value to the organization.
Attributes – Characteristics that gives additional information.
Relationships - logical linkage between two entities that describes how those entities are associated with each other.
What are the two types of Attributes?
Identifiers - Used to specify a unique characteristic of the entity. This will be used to identify the entity.
Descriptor - Merely used to provide more information on the entity. This does not uniquely identify the entity.
What is Cardinality?
cardinality usually represents the relationship between the data in two different tables by highlighting how many times a specific entity occurs in comparison to another.
What are the different types of Cardinality?
One-to-One - A single instance of one entity is associated with a single instance of another entity.
One-to-Many - An instance of an entity (called the parent) is associated with zero or more of another entity (called the child).
Many-to-Many - Many instances of one entity are associated with many instances of another entity.
What are the guidelines for a ERD?
Singular
Named after an Entity
Mixed Case
Same Naming
Name some ways to check data integrity
Entity - A way to uniquely identify every row in a table.
Domain - Refers to the data type and nullability of a column.
Reverential - Primary and foreign keys remain synchronized.
What is a non-decomposable column?
A column that can’t be broken down into more columns.
What are the advantages of using a non-decomposable column?
Easier to Update
Easier to Query
Specific Data Integrity
What are the rules for Normalization?
1 – Dependencies Between Data are identified.
2 – Redundant Data is Minimized.
3 – The data model is flexible and easier to maintain.
What are the different normal forms?
Zero Normal Form – Before we start the normalization steps, we look at our question and list all the attributes we will need in our database.
First Normal Form - An entity is in the first normal form if it contains no repeating groups.
Second Normal From - A relationship is in the second normal form (2NF) if it is in the first normal form, and all its attributes depend on the whole primary key.
Third Normal Form - A relationship is in the third normal form (3NF) if all the attributes are non - transitively dependent on the primary key.
Name different types of objects in SQL
Literal Values - A literal value is an alphanumerical, hexadecimal, or numeric constant.
Delimiters - Used to allow the use of reserved keywords as identifiers.
Comments - There are two different ways to specify a comment.
Identifiers – Identify Database Objects.
Reserved Keywords – Set of names with a reserved meaning.
Name different types of a Data Integrity?
Entity Integrity - a way of distinguishing between different entities. In other words, a way to uniquely identify every row in a table.
Domain Integrity - concerned with ensuring that column values fall within an acceptable range of values (the domain). Domain integrity also refers to the data type and nullability of a column.
Referential Integrity - refers to the requirement that primary and foreign keys remain synchronized between parent and child tables.
What can the Alter Table Statement do?
Add a column.
Remove a constraint.
Change a column data type.
Add a check constraint.
Add a foreign key.
Add a default constraint.
Remove a table or column.
Add a unique constraint.
Add a primary key.
What are the Advantages of Indexing?
Much quicker path to any row in a table.
Enforce entity integrity.
Improve the performance of queries that use joints.
Improve the performance of queries that use the ORDER BY clause.
What are guidelines to clustered indexing?
Only one clustered index can be created per table.
The leaf pages are the table’s data pages, and the rows are physically stored in order to the index key.
Clustered indexes are smaller than non-clustered indexes.
What are guidelines to non-clustered indexing?
Up to 249 non-clustered indexes can exist on a table.
The logical order of the rows is different than the physical order of the data.
Create a clustered index before creating any non-clustered indexes.
What are guidelines to Composite Indexing?
Up to 16 columns can be used in an index. The combined size of the columns cannot exceed 900 bytes.
The order in which the columns are used in the index is very important
When building a composite index, use the most unique column as the first column.
What are the columns that can be indexed?
Primary Keys and Foreign Keys
Columns you often search.
Cover the Query
Search for a range of values
Sort the results of a query.
Why do we use joins?
To create a single query that returns data from multiple tables.
What are the different types of Joins?
INNER JOINS
On the right is a visual representation of
an INNER JOIN between two tables. Only
the records that have a link to both tables
will be displayed.
Also known as an equi-join.
An INNER JOIN cannot be nested inside a
LEFT JOIN or RIGHT JOIN. There must
always be a relational link between tables
used in a join query.
OUTER JOINS
Outer joins differ from INNER JOINs in that
rows that do not have matches in a joined
table can be returned.
LEFT JOIN
All records from table A will be displayed
with the related records from table B. If
there are no related records, a NULL will
be displayed.
RIGHT JOIN
All records from table B will be displayed
with the related records from table A. If
there are no related record, a NULL will be
displayed.
What is a Sub-Query?
A simple example of a sub-query would be to return all the titles of books that have a price less than that of the average price of all the books.
What is a Common Table Expression?
The common table expression (CTE) is a powerful construct in SQL that helps simplify a query. CTEs work as virtual tables (with records and columns), created during the execution of a query, used by the query, and eliminated after query execution. CTEs often act as a bridge to transform the data in source tables to the format expected by the query.
What is the Syntax for a Common Table Expression?
WITH ghostTableName
(Col1, Col2)
AS
(
SELECT Col1ID, SUM(Col2)
FROM Table
GROUP BYCol1ID
)
SELECT Columns
SELECT Col1ID, SUM(Col2)
FROM Table
INNER JOIN ghostTableName
GROUP BY Col1ID
What are scripts and batch?
A query is a single SQL DML statement.
A batch is a collection of one or more T-SQL statements.
The SQL script file and Query analyser window can contain multiple batches.
If there are multiple batches, then the batch separator keyword terminates each batch.