Week 8 Flashcards

1
Q

What does Auto Increment do?

A

Auto Increment allows a unique number to be generated automatically when a new record is inserted into a table

Typically for primary key

In MySQL, assign AUTO_INCREMENT to a column

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

What is an example of Auto Increment in SQL?

A

ALTER TABLE Persons AUTO_INCREMENT 100;

This starts the number at 100

And will increment up or down depending on what is coded

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

What is an Index?

A

A data structure (e.g., a B-Tree) designed to improve the speed of data retrieval from a table

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

What are the benefits of using Indexes in Databases?

A

Indexes help optimize query performance by allowing faster lookups, similar to a book’s index

Using indexes is particularly helpful for columns that are frequently searched, filtered, or sorted

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

What is a View in SQL?

A

A View is a virtual table based on the reulst-set of an SQL statement

eg.

CREATE VIEW AS
SELECT C2, C3, C5, C7
FROM T1
INNER JOIN T2…
INNER JOIN T3…

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

What are the 2 types of Views in SQL?

A

Horizontal View - Focus only on rows

Vertical View - Focus only on columns

You can also join Views to get a Grouped and joined view

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

What is View Updatability?

A

All updates to base table are immediately reflected in all views that encompass that base table

Similarly, we may expect that if a view is updated then the base table(s) will reflect that change

But not all views are updatable

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

What is required for a View to be updatable?

A

The DBMS must be able to trace any row or column back to its row or column in the base table

eg. cant use functions like join or aggregation only simple ones to make sure the view is updatable

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

What are Migrating Rows?

A

CREATE VIEW Emp_D20 AS
SELECT *
FROM Emp
WHERE deptNo = 20;

What will happen if we update the Emp_D20 as follows?

UPDATE Emp_20
SET deptNo = 10
WHERE empNo = 1003;

This employee disappears in this view, which is called migrating rows

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

What is the WITH CHECK OPTION?

A

The WITH CHECK OPTION is used when creating a view to ensure that:

Insertions or Updates conform to the view’s definition: Any new rows added (via INSERT) or modifications made (via UPDATE) must satisfy the conditions defined in the view’s query

Rows cannot “migrate” out of the view: If an update causes a row to no longer meet the view’s conditions, the operation will fail

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

What is COMMIT and ROLLBACK?

A

COMMIT - Causes all outstanding changes you have made to become permanent

ROLLBACK - Causes all uncommited changes to be discarded

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

What is Physical Database Design (PDD)?

A

The process of producing a description of the implementation of the database on secondary storage

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

What are the steps for translating a Logical Data Model into a physical implementation?

A
  1. Translate logical data model for target DBMS
  2. Design file organisations and indexes
  3. Design user views
  4. Design security mechanisms
  5. Consider controlled redudancy
  6. Monitor and tune the opeational system
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the benefits of Physical Database Design (PDD)?

A

Ensures:

The database is efficient, secure, and easy to maintain

It meets the requirements of the business and the users

It is optimized for the specific DBMS and workload

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

What are 3 ways to represent Derived Data?

A
  1. Use generated column
  2. Create a view

3 Use triggers

Triggers are stored programs execute automatically to respons to specific events such as inserting, updating or deleting data

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

How is a Database Stored?

A

Stored as a collection of files. A database file is partitioned into fixed-length storage units called blocks (or pages)

Block/Page - A contiguous sequence of sectors from a single track

Data blocks are the smallest units of storage allocation and data transfer

17
Q

Where do data operations take place and where is the DB stored?

A

Operations on data happen in volatile memory eg. main memory, cache memory

Entire DB is stored on non volatile memory eg. magnetic disk, optical disk tape, flash drives etc.

Entire DB is backed up on Stable storage eg. RAID

18
Q

What is File Organisation and what are the ways to ogranize blocks/pages in a file?

A

File Organisation - Physical arrangement of data in a file

Ways to organise blocks/pages in a file:

Heap (unsorted) files: records placed on disk in no particular order

Sequential (ordered) files: records are ordered by the value of a specific attribute

19
Q

What is a Non-clustered (secondary) index?

A

an index which maintains a logical ordering of data rows without altering the physical ordering of the rows

A table could have several secondary indexes

Foreign keys good candidates for non clustering indexes

20
Q

What is Denormalization?

A

Process of trying to improve the read performance of a database, at the expense of losing some write performance, by adding redundant copies of data or by grouping data

when to use?

  • If performance is unsatisfactory and a relation has a low update and a very high query rate
21
Q
A