Databases Flashcards

1
Q

What is a database?

A

A structured persistent store of data. Stored on the secondary storage devices of a computer system

Provide security, auto backups and users with controlled access to data they need

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

Benefits of databases?

A
  • Make it fast to: access data, update data, search for data and present data in a suitable way
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the layers of a Database?

A

External level: What the user sees. Acts like a filter on data in the database Designed to be useful for a particular job. User friendly UI. Hides unnecessary/restricted data. Allows user to interact with DB

Conceptual view: Describes structure of DB, entities, attributes, data types, relationships, validation, tables. Hides details of physical storage structures

Physical: How the data is actually stored in the DB, works with OS and DBMS to store and retrieve data from storage devices

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

What is data security?

A

Keeping data safe from accidental or deliberate loss and malicious attacks.

Controls Who has access to the database and what they are permitted to do

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

What are files?

A

Data stores on a computers secondary storage medium that have names and are stores of binary data
Can be a program, word processed document, image or music

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

What are serial data files?

A

Records organised one after another

Only possible way to storage files on mediums such as tape

Each data file is as large as the data to be stored

No empty records = efficient

Slow as it has to read through each data record until relevant record is found

If data is modified then the complete altered file has to be re-written back to storage medium. Temp file created and replaces original until process is complete

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

What are sequential data files?

A

Same as serial but records are stored in order of a designated key field (Eg: alphabetical)

Records can be found easier

Data modification still raises same issues as serial

Not great for data that has no particular order as data has to be sorted often

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

What is indexing?

A

Speed up searches

Software searches for the start of the right section (like a book chapter), then directs the search to the right part of the main data store. After that a sequential search can look for the item required

Records match length of data to be stored

No wasted space

Deleting a record will only delete index number, data still remains

New records are added to end of files and index number is increased

Eventually DB will have large amounts of wasteful data that is not indexed. Can be solved by rewriting the file and therefore removing any un-indexed data and re-indexing the rest

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

What is an indexed sequential data file?

A

Used for large Sequential Data Files
- Stored in order of key field AND index

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

What is a random access data file?

A

Each record is ID with a record number in sequence and each record occupies same space

Quick access to data as it can calculate position based on record number

Wasteful of storage as EVERYTHING is stored with same amount of memory

Each time new file is added it is added to the end and the RN is Incremented

When records are removed only the data is deleted, leaving an empty record. Overtime there can be many blank records

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

What are fixed length fields?

A

Suitable amount of space In a file is reserved for data

Any unused bytes are packed with a character such as a space

Less space efficient however processing is more straightforward because bytes can be counted to reach desired point. (After set ‘n’ number of bytes you will move onto next field)

Quick to search

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

What are variable length fields?

A

Only store as much data as is needed. Eg “Fred’ takes 4 bytes and ‘Jennifer’ takes 8 bytes

Space efficient

Processing is harder as finding a particular record requires checking all the preceding entries sequentially

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

What is a flat file database?

A

Simple databases with one table

A single spreadsheet is an example

used for simple data-handling requirements

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

What is a relational database?

A

Multiple related tables

Each table represents a single entity (real world object or person)

Required for the storage of more complex data

Tables are linked via common attributes to create relationships (Primary keys —> foreign keys)

Reduces amount of duplicated data

Entity is anything about which we store data. They have attributes (characteristics eg: student name, ID, subject level)

Tables consist of Tuples (records)

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

What is a hierarchal database?

A

Multiple tables
Tree like structure
Each child node linked to parent node

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

Structure of relational databases? (Including primary, secondary and foreign keys)

A

Use fixed length fields

Each column contains 1 data type

No rule about order of rows in a table. When order is required indexes are added

No rule about order of columns

No two rows can be identical

One column must be primary key therefore making each row unique

Primary key is used to link a table to the foreign keys of other tables. Relationships link them together and are produced by having repeated fields across tables (foreign key)

Secondary keys are not necessarily unique but can be useful for quick searching

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

What are entity-relationship diagrams? Draw a one-to-many relationship, many-many relationship and one-one relationship

A
  • A data modelling technique used to define a relational database
    RELATIONSHIP DIAGRAMS CAN BE FOUND IN PHOTOS
    -In relational databases we want tables to be related by one-to-many relationships
    -A one-to-one relationship suggests that 2 entities should be in the same table
    -A many-to-many relationship suggests the need for at least one more table to separate entities
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is hashing?

A

Method of transforming a string of characters in a record into a shortened form that can be used as a disk address

This shortened form can be used to access a record from a database more easily than by using the complete original string

Typically multiple records can produce the same hash values. In this case the data is located in the next available space on the storage medium, so some serial searching may be necessary

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

What is data redundancy?

A

Unnecessary duplication of data in database
- Repeated fields etc. We need some repeated fields to make links but to many leads to errors and wastes storage space

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

What is referential integrity?

A

ensures data integrity.
Referential Integrity refers to the accuracy and consistency of data within a database.

REMEMBER ####
Makes sure all foreign keys link to an existing/valid primary key.
Also makes sure if a primary key is deleted/updated, foreign keys are no longer valid

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

What is a DBMS? What does it create and what does it provide?

A

Database management system that creates and maintains a database. Eg: Microsoft Access

Creates and uses: the structure, queries, views, individual tables, interfaces and outputs

Provides: security, backups, index updating, enforcement of referential integrity and facilities to update and interrogate the DB

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

What is transaction processing?

A

attempts to provide a response to the user within a short time frame.
not as time critical as real time
features limited range of operations planned in advance, such as a bank account balance enquiry or withdrawal

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

What is CRUD?

A

relational databases must have certain basic functionality to be useful

Create, Read, Update, Delete

match to; INSERT, SELECT, UPDATE,
DELETE. SQL commands

3 of the commands result in transaction taking place

24
Q

What is data integrity?

A

transaction must not allow DB to be damaged else DB will be inconsistent

DBMS ensures that DB changes from one consistent state to another

25
Q

What is data corruption?

A

opposite of data integrity

caused by; hardware/software failures or electrical glitches

can also be operator error or malpractice

26
Q

What is ACID?

A

protects integrity of a DB

27
Q

What does the A in ACID stand for?

A

-Atomicity = a change is either completely

performed or not at all

28
Q

What does the C in ACID stand for?

A

-Consistency = a transaction must take the whole DB from one consistent state to another (bank transaction; total money in system must remain the same)

29
Q

What does the I in ACID stand for?

A

Isolation = a transaction must be performed in isolation so that the other processes/users cannot access that data until it is in a consistent sate
while an operation is being performed on a record, the record is locked

30
Q

What does the D in ACID stand for?

A

-Durability = once committed, a change must not be lost due to any subsequent system failures

31
Q

What is the aim of DB normalisation?

A

makes a DB more efficient process by which a collection of data is gradually organised into tables through a series of steps

cumulative and the stages have to be worked through in succession

makes sure the data in each table is all properly and completely related together

attributes in a relation must not themselves be sets, multiple values for one tuple are not allowed

32
Q

What is the First Normal Form (1NF)?

A

Database has:
- a Primary Key (ID)
- Atomic Data (data item that cannot be broken down any further.)
- No repeating fields

33
Q

What is the Second Normal Form (2NF)?

A

Check data is in 1NF

Any partial dependencies have been removed. (One or more fields depend on only part of the primary key)

34
Q

What is the Third Normal Form (3NF)?

A

check that the data is in 2NF

No no-key dependencies.

Remove any columns that are not dependent on the primary key
- “every non-key attribute in a table must depend on the key, the whole key, and nothing but the key”

35
Q

what are queries?

A

main use of DB’s

used to isolate and display a subset of the data in a database. -They can take related data from multiple tables and present them in an easy-to-understand way

used as the basis for a screen form of a printed report so that filtered data can be presented in some clear or standard way

36
Q

What is the main way queries are performed?

A

Query By example (QBE) comes with most off the shelf DBMSs. User is presented with GUI into which can be dropped the fields required as well as setting up conditions to filter the results

37
Q

What is SQL?

A

the code behind queries that allow for more flexible ones to performed

Fields required are separated by commas . SELECT is used to extract the required data from the data set and conditions can be applied using the WHERE clause

Conditions can be tailored exactly to meet the operational requirements

38
Q

What happens if multiple tables are being queried in one SQL statement?

A

dot notation is used
eg; if “customername” and “tableorder” are both being queried the fields will be written as “customername.name” and “tableorder.order”

39
Q

What are wild card operations?

A

‘*’ means everything
’%’ means one or many characters
‘_’ means just one character

40
Q

What else can SQL do?

A

has features that allow the creation and modification of DB’s
rich set of commands and operators that can perform any data processing required on a relational DB

41
Q

What are some other SQL commands?

A

CREATE = allows creation of tables
INSERT = allows data to be entered in DB’s
DROP = allows SQL program to remove indexes, tables, fields and whole databases (structural removal)
DELETE = allows the removal of data from a table (data removal)
JOIN = combines data from two or more tables using a duplicated field such as a customer number in both the customer table and the order table

42
Q

primary key def

A

A primary key is a unique identifier for each record in the table.

43
Q

What is a entity?

A

An entity is a category of data to be recorded in a database, entities have attributes.

44
Q

What is an attribute?

A

The data attached to an entity. For example the entity Dentist might have the attribute name.

45
Q

What is the need for a secondary key?

A

A secondary key is indexed allowing for faster

searching.

46
Q

What are the three degrees of relationships in a relational database?

A

One to one, One to many, Many to many.

47
Q

What is a foreign key?

A

A foreign key is the attribute which links two tables together.

Helps with data redundancy.

48
Q

What needs to be done in the case of a many to many relationship?

A

An extra table is needed in order to link both tables consisting of foreign keys.

49
Q

What is a composite key?

A

A primary key that consists of more than one attribute.

50
Q

What is an issue likely to arise when using a flat file structure?

A

Redundant data and data inconsistencies.

51
Q

What are the different types of relationship types (entity-relationship diagrams)? With examples

A

One to One
Example:
Country, Capital City (A Country only has one capital)

One to Many
Example:
Owner, Vehicle (One Owner, may have many vehicles)

Many to Many (CANT EXIST IN A DATABASE)
Teachers, High School Students (Many Teachers, have many students in a high school)

52
Q

What is the problem with many-many relationships

A

Difficult to make logical links between them / query the data, so many-to-many relationships cant logically exist in a database

52
Q

How can you fix a many-to-many relationship?

A

You have to brake the relationship down.

An example of this is:

Many teachers-to-Many Students

BREAK IT DOWN

A teacher to Many Classes. Many Classes to Many Students
https://gyazo.com/52e36f983c42de174d300b6fef35e809

There is still a many to many relationship so…

BREAK IT DOWN MORE

A teacher to many Classes. A class to Many Registers. A register to Many Students.
https://gyazo.com/319232d7bb93374efdf7adf1940345a6

53
Q

What is an Associative entity?

A

Breaks up a many-to-many relationship
Allows a user to make sensible tables with a minimum amount of data redundancy.

54
Q

How can you tell if a key, is a foreign key? And what would be a foreign key in a hospital patient table.

A

The foreign key will exist in one table as the primary key and act as the foreign key in another.

An example of this is:
DoctorID would be the foreign key in the Patient table.

55
Q

Explain what is meant by the term “Referential Integrity” and how this could potentially be broken.

A

1.) DB/Relationships are consistent, each foreign key links to an existing/valid primary key

2.)If a primary key is deleted/updated foreign keys are no longer valid