Databases Flashcards

(49 cards)

1
Q

what is a database?

A

They are structured sets of data. They are organised in such a way that they can be easily managed, accessed, updated and analysed.
Eg. a relational database - made up of tables

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

what is a flat file?

A

The simplest form of a database - it is a single file, normally organised in a table structure with rows and columns

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

how would you write an entity description?

A

Entity1 (Attribute1, Attribute2, … )

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

what is a relational database?

A

a set of tables whose records are linked by certain fields. Each table contains data on one entity. the tables can be linked together using foreign keys (a relationship)

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

what is the purpose of an entity identifier?

A

it is used to uniquely identify the entity - it is the primary key in a relational database

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

What is a record?

A

All the fields relevant to an entity - kind of like a row in a table

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

what is an entity?

A

it is a category of object, person, event or thing of interest to an organisation, about which data is to be recorded

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

what is a field/attribute?

A

it is a property or characteristic of an entity - it is kind of like a column in a table

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

what is the primary key?

A
  • it is an entity identifier that uniquely identifies records in an entity. Data in the entity will be sorted by this by default
  • denoted by being underlined in the entity description: eg. Dentist (DentistID, Title, Firstname, Surname, Qualification)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is a composite primary key?

A
  • its a primary key made up of multiple fields - used to maintain uniqueness
  • eg. a customer order with multiple order lines would have OrderNumber + OrderLine as composite primary key
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is a secondary key?

A
  • any other fields in the table that aren’t the primary key
  • makes sure that records in the database remain searchable since a customer/user may not know the relevant primary key value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is a foreign key?

A
  • its an attribute that creates a join between tables
  • the attribute is common to both tables
  • foreign key in one table = primary key in the table its linked to
  • denoted by being in italics - eg. Patient (PatientID, Title, Firstname, Surname, Address, Telephone, DentistID)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can entities be related + how are they represented in an entity relationship diagram?

A

One-to-one:
- eg. husband + wife, country + prime minister
- shown by 2 rectangles (for entities) joined by one straight line

One-to-many:
- eg. school + pupils, mother + child
- shown by 2 rectangles joined by a straight line on one side and birds legs on the other

Many-to-many:
- avoided where possible (eg, through normalisation)
- eg. actors + films, products + components, student + course
- represented by 2 rectangles joined by birds legs on either end

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

what is an entity relationship diagram?

A

it is a diagramatic way of representing the relationships between entities in a database

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

how would you remove a many-to-many relationship?

eg. you have 2 tables:
- student (studentID, name, address)
- course (courseID, subject, level)

A

create a middleman table eg:
- student (studentID, name, address)
- enrolment (_studentID_, _courseID_)
- course (courseID, subject, level)

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

what is referential integrity?

A

no foreign key in one table can reference a non-existent record in another table - eg. can’t add a subscription for a customer if the customer ID doesnt exist in a record

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

what is relational database structure?

A
  • tables in the database = relations
  • one database will have one or more relations
  • relation has rows - aka records
  • each record has fields/attributes - like columns
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

how are databases indexed?

A
  • records automatically indexed by primary key
  • can also be indexed by any other secondary key (secondary index)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

what is normalisation?

A
  • it is the process used to come up with the best possible database design
  • 3 stages: 1st normal form (1NF), 2nd normal form (2NF), 3rd normal form (3NF)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

what should a normalised database look like?

A
  • no data is unnecessarily duplicated
  • data is consistent throughout the database
  • table structure should be flexible enough for you to enter as many or as few items as required
  • structure should allow as complex queries to be made
21
Q

what are the properties required of a database in first normal form?

A
  • no repeating attributes/groups of attributes
  • must have a primary key
  • atomic - only one data item in one field
22
Q

how can you make a many to many relationship into 1NF?

A

use a link table/middleman table

23
Q

what are the features of a database in second normal form?

A
  • already in 1NF
  • no partial dependencies - one or more attributes depends on only part of the primary key (only works if it is a composite primary key)
24
Q

what are the features of a database in third normal form?

A
  • already in 2NF
  • contains no non-key dependencies - the vvalue of an attribute is determined by the value of another attribute which is not part of the key
  • “all attributes are dependent on the key, the whole key, and nothing but the key”
25
what are the advantages of a normalised database?
- no data redundancy (data that appears in more than one table) - less inefficinecy + inconsistencies in data - data integrity is maintained - no duplication of data + only need to modify 1 table if a change needs to be made - smaller tables with fewer fields = faster searching, sorting + indexing - saves storage space- data only held once - can't delete records accidentally on the one side of a one to many relationship
26
what is SQL?
- stands for Structured Query Language - declarative language - used to query + update tables in a relational database
27
how is data for a database captured?
- survey results may be manually inputted - magnetic ink character recognition (MICR) on bank cheques - optical mark recognition (OMR) used on multiple choice tests - Optical character recognition (OCR)
28
how is data exchanged?
- using EDI - electronic data interchange - enables data transfer from one computer to another without using human interaction
29
what is the SELECT statement used for?
to extract a collection of fields from a given table(s)
30
what is the syntax for the SELECT statement?
`SELECT` (the fields to be displayed - * if all) `FROM` (list the table(s) data will come from) `WHERE` (search criteria, the conditions) `ORDER BY` (list the fields that results are to be sorted on, ascending by default)
31
what is the wild card operator syntax?
`LIKE "comp%"` the percentage is the important bit - looks for anything in the database starting with comp followed by anything
32
in the WHERE clause, how do you determine a range?
`BETWEEN ... AND` including the 2 values that define the limit
33
in the WHERE clause, what does the IN operator do?
specify multiple possible specific values for a column for the record to be considered
34
how do you reference an empty field?
`IS NULL`
35
how do you write a data in SQL?
`#DD/MM/YYYY#` you need to enclose it in the hashes
36
when are semicolons used?
at the end of each SQL statement - the standard way to separate them DONT put it within a statement
37
what orders can be specified using ORDER BY?
`ASC` - ascending `DESC` - descending
38
what is the syntax used to extract and combine data from 2 or more tables (without using join)?
```SELECT table1.fieldName, table2.fieldName, ... FROM table1, table2, ... WHERE (table1.fieldName1 = table2.fieldName1)```
39
what is the syntax used to extract and combine data from 2 or more tables (using join)?
```SELECT table1.fieldName, table2.fieldName, ... FROM table1 JOIN table2 ON table1.fieldName1 = table2.fieldName1 WHERE ...```
40
how do you define a table using SQL?
using `CREATE TABLE` ```CREATE TABLE ( column1 DATATYPE, column2 DATATYPE, column3 DATATYPE, ... )```
41
what are the most commonly used data types when creating a table with SQL?
- `CHAR(n)` - character string of fixed length n - `VARCHAR(n)` - character string of variable length, max n - `BOOLEAN` - TRUE or FALSE - `INTEGER, INT` - integer - `FLOAT(a,b)` - number with floating decimal point - a = max no of digits before decimal point, b = max no of digits after decimal point - `DATE` - stores day, month, year values - `TIME` - stores hour, minute, second values - `CURRENCY` - formats numbers in currency used in your region
42
how to add a column using SQL?
```ALTER TABLE table ADD column1 DATATYPE```
43
how to delete a column using SQL?
```ALTER TABLE table DROP COLUMN column1```
44
how to change data type of a column in SQL?
```ALTER TABLE table MODIFY COLUMN column1 NEWDATATYPE```
45
how to create a foreign key using SQL?
done during CREATE TABLE ```FOREIGN KEY column1 REFERENCES table2(column1)```
46
how to set the primary key in SQL?
done during CREATE TABLE: ```PRIMARY KEY (column1, ...)```
47
how to add a record to a table in SQL?
```INSERT INTO table1 (column1, column2 ...) VALUES (value1, value2 ...)```
48
how to update a record in a table in SQL?
```UPDATE table1 SET column1 = value1, column2 = value2, ... WHERE columnX = value```
49
how to delete a record in a table in SQL?
```DELETE FROM table1 WHERE columnX = value```