Tables, Normalization, Relationships Flashcards

1
Q

table constraints

A

column attributes that restrict data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

table constraints : PRIMARY KEY

A

a column whose values uniquely identify each row or particular entry in a table (for a table of persons a social security number would be a good primary key because they should be unique for each person)

-Primary Key columns must have a value in each row, and those values must be unique to the table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

table constraints : FOREIGN KEY

A

a column in one table that references a column in another table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Composite key

A

If a group of columns are combined to uniquely identify a row, this is called a composite key.

-it is two or more columns acting together as a primary key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

table constraints : UNIQUE KEY

A

a column whose values must be unique in each row.

-example: email addresses for people. not two people can have the same email addresses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

table constraints : NOT NULL

A

The column must have a value in each row

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between a primary key and a unique key?**

A

Primary key will not accept NULL or duplicate values whereas Unique key can accept one NULL value. A table can have only primary key whereas there can be multiple unique key on a table. A Clustered index automatically created when a primary key is defined whereas Unique key generates the non-clustered index.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

table constraints : CHECK

A

the column values must meet some criteria

ex: a requirement that the ages of all rows in a table of people be above 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between a primary key and a foreign key?**

A

primary key is a column whose values uniquely identify each row or particular entry in a table
-no nulls or duplicates allowed

a foreign key is a column in one table that references a column in another table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Database normalization

A

Database normalization is the process of designing your database in such a way that
you have no composite columns,
little to no redundant data in a table, and that your data dependencies/relationships make sense.

There are as many as six or seven stages of normalization, but generally a database is acceptable if it reaches the 3rd stage, called Third Normal Form

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Join Table**and what are the types?

A

a join table or an association table

A JOIN is a means for combining columns from one (self-join) or more tables by using values that are common to each. ANSI-standard SQL specifies five types of JOIN : INNER , LEFT OUTER , RIGHT OUTER , FULL OUTER and CROSS .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Normalization

A

-it is driven by business requirements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

TCL : Transaction Control Language

A

-The process of making a change to your data permanent is called committing, and most databases have a feature called autocommit turned on by default

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Transaction Control Language : COMMIT, SAVEPOINT, ROLLBACK

A

Use SAVEPOINT command to save a “snapshot” of your database at any point while executing a series of commands.

You can have multiple save points with different names, or you could “move” your existing save point by reusing it.When you realize that a mistake has been made, you can use the ROLLBACK TO command to revert any changes that have been made to a database since a specified save point.

You cannot roll back to a period before a save point was made, and you cannot rollback or undo a rollback action.
Additionally, you cannot rollback past a commit statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Joins and Unions

A

-Joining two tables requires that each table have a column that tracks the same data.
(inner joins, left join, right join, outer join)

  • Unions: a combination of two distinct select statements in a single result set.
  • the first column of your first SELECT statement will be lined up with the first column of your second SELECT statement, and so on.For this reason, your UNION statement must obey two rules: First, the number of columns returned by both SELECT statements must be the same.Second, the data types of each column in the first SELECT statement must match the data types of each column in the second.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

As keyword

A

used to specify an alias

17
Q

Procedures and Functions

A

-A function in SQL is a series of SQL statements that accepts multiple inputs, and returns a single result (a scalar value)

18
Q

User defined function

A

CREATE FUNCTION function_name ( input type 1);
return type

  • first you use the CREATE FUNCTION statement, followed by the function’s name, and then the input parameters and their types between parenthesis.Then you state the return type of the function – does it return an INTEGER, a NUMBER, a VARCHAR, etc.The actual logic goes between the BEGIN and END statements, and at some point in there you RETURN a value.
19
Q

Stored procedure

A

A stored procedure is similar to a function in that it’s a series of SQL statements that can be invoked by name.

-can return multiple output values

20
Q

** differences between a stored procedure and a function*****

A

The differences between a stored procedure and a function is a line that is blurred to different degrees by different databases, but usually a stored procedure can return multiple output values or even multiple columns or tables.
A stored procedure can also often be invoked directly by code written in other programming languages, like Java or Python.

-sits in the database rather than being sent to the database. provides safety and security.

Stored procedures can’t be part of a statement or expression the same way functions can.Instead, you have to explicitly run a stored procedure by using the CALL or EXECUTE command.

-best to use stored procedures