(4.10) Fundamentals of databases Flashcards
(23 cards)
What is an entity?
An entity is something about which data is stored
What is an attribute?
Characteristics or other info about entities
What is an entity identifier?
- In a database, each entity requires a unique identifier
- an entity id is an attribute for an entity, which is unique within that table
- sometimes entity ids are multiple attributes for uniqueness
What is an entity description?
- An entity description describes how data will be stored about entities
- Underlining shows the attribute/s that form the entity identifier
ex.
Contacts (Name, PhoneNumber, Email, Age, etc..)
Relational databases: how are tables linked together?
Relational databases link tables together using common attributes (relational keys), there are 3 types of relationship:
* one-to-one
* one-to-many
* many-to-many
Entity relationship diagrams
- entity relationship diagrams show the relationships between tables
- one-to-one : ——
- one-to-many : —–<
- many-to-many : >—–<
Primary and foreign keys: what are they?
A Primary key is an attribute that is a unique identifier for every entity in a table, e.g. an IDNumber
when tables are linked by attributes, the attribute must be a primary key in one table and a foreign key in the other
A Foreign key is an attribute in a table which is a primary key in another, related, table
attributes can be combined to form a composite primary key
What has to be created when linking a many-to-many relationship?
When linking a many-to-many relationship you have to create a new link table
Why are databases normalised and how?
Databases are normalised so that they can be efficient while keeping the data accurate and reliable:
* Allows for faster searching and sorting
* They are easier to maintain
* Duplication of data is lower and higher data consistency
* reduces the number of update, insertion and deletion anomalies
Normalising involves ensuring entities have no repeated or redundant data
Databases: what is first normal form?
- Doesn’t contain any repeating attributes
- Has atomic data (no column has more than one value)
ex. phone number is atomic, whereas Firstname, Lastname is not
Databases: what is second normal form?
- All of first normal form (No repeating attributes, atomic data)
- Has no partial key dependencies
(this is when a non-key attribute doesn’t depend on the whole of the composite key)
E.g. a table called CourseEnrollment:
StudentID, CourseID, StudentName, CourseName
- StudentName depends only on StudentID
- CourseName depends only on CourseID
How to fix this:
Student(StudentID, StudentName)
Course(CourseID, CourseName)
Enrollment(StudentID, CourseID)
Databases: what is third normal form?
- All of first normal form (No repeating attributes, atomic data)
- All of second normal form (partial key dependencies removed )
- Has no non-key dependencies
(All non-key attributes depend on the key, the whole key and nothing but the key)
Client server databases: what do they do?
- Client server databases provide simultaneous access to a database for multiple users
- When different users try to access the same field at the same time, concurrent access occurs
What is concurrent access?
Concurrent access is the problem of
updates being lost if two clients edit a record at
the same time
How can concurrent access be fixed?
Concurrent access can be managed
by:
- record locks - while one user is using a record, it is locked to other users
- serialisation - requests to edit a record are queued
- timestamp ordering - each command is assigned a timestamp, marking when it was initiated
- commitment ordering - an algorithm is used to work out an optimum order, taking into account the impact of the command on the rest of the database
What is a declarative language?
The programmer describes the result that is required rather than the process that should be followed
SQL: SELECT
- Used to retrieve data
SELECT < attribute > FROM < table > WHERE < condition > ORDER BY < ASC/DESC >
(order by is optional)
SQL: UPDATE
- Used to modify the attributes of an existing entity
UPDATE < table > SET < attribute > = < value > WHERE < attribute > = < value >
SQL: DELETE
- Used to remove entities
DELETE FROM < table > WHERE < condition >
SQL: INSERT
- Used to add new records to an existing table
INSERT INTO < table > (< column1 >, < column2 >, …) VALUES (< value1 >, < value2 >, …)
but can be simplified to
INSERT INTO < table > VALUES (< value1 >, < value2 >, …)
when all of the columns in the table are being used in the correct order.
SQL: Wildcards
- Can be used in SQL to specify any possible value
(*)
Defining a table with SQL
- The CREATE command allows new tables to be made within a database
- It specifies: the name, its attributes, their data types
- Entity identifiers are also specified (primary & secondary keys)
SQL data types (for defining tables)
- Fixed length string - CHAR(size)
- Variable length string - VARSIZE(size)
- Integer - INT(size)
- Number with fractional part - FLOAT(size, precision)
- Date - DATE
- Date and time - DATETIME
- Time - TIME
- Year - YEAR