Databashantering Flashcards
ER Model
- Makes a visual model of the database
- Easy to understand and interpret
- Physcological representations of how tasks should be carried out
- Easy to convert into relations
Super key
A superkey is an attribute or set of attributes that is used to uniquely identifies all attributes in a table, such as ID or phone-number
Candidate key
A minimal super key. It has the least possible number of attributes to still be a super key
Weak entity set
- Do not have sufficient attributes to form a primary key
- Depend on another entity
One-to-one
For example, one person can only be married to one person
One-to-many
For example a scientist can invent many inventions, but the invention is done by one specific scientist
Many-to-many
For example, classmates
Data redundancy
- When the same piece of data can be found in multiple places
- Leads to update anomalies
Anomalies
Inconsistencies or errors that can arise when working with relational databases
Type of anomalies
- Update anomalies
- Deletion anomalies
- Insertion anomalies
Normalisation
- Fix the problem with data redundancy and anomalies
- Efficiency
- Divides larger table into smaller and linked them using relationships
Advantages with normalization
- Data consistency: Normal forms ensure that data is consistent and does not contain any redundant information.
- Data redundancy: Normal forms minimize data redundancy by organizing data into tables that contain only unique data
- Response time: Normal forms can improve query performance by reducing the number of joins required to retrieve data. This helps to speed up query processing and improve overall system performance.
- Database maintenance: Normal forms make it easier to maintain the database by reducing the amount of redundant data that needs to be updated, deleted, or modified.
- Database design: Normal forms provide guidelines for designing databases that are efficient, flexible, and scalable. This helps to ensure that the database can be easily modified, updated, or expanded as needed.
Steps of database normalisation
- 1NF: Every table have a primary key. The tables cannot be broken down further. Each value needs to be in its own column
- 2NF: Any column that is not the primary key needs to be dependent on the primary key.
- 3NF: Any column that is not the primary key needs to be dependent on the primary key (and no other column)
Has no transitive functional dependencies - BCNF: A stricter version of 3NF, BCNF ensures that every non-trivial functional dependency is a superkey. This means that no partial dependencies or transitive dependencies are allowed.
What does 3NF and BCNF give you?
- Lossless join
It should be possible to project the original relations onto the decomposed schema, and then reconstruct the original - Dependency Preservation
It should be possible to check in the projected relations whether all the given FD’s are satisfied
Inner/outer join
- Inner join joins all matching rows
- Left outer joins all matching rows and keeps the rows of the left table
- Right outer joins all matching rows and keeps the rows of the right table
- Full outer join joins all matching rows and keeps the other non-matching rows
Extended Relational Algebra
- An extension of relational algebra
- Introduces aggregate functions (sum, average, count, min max)
- Grouping
- Set Difference
- Division
- Allows more complex queries
SQL Triggers
- Stored programs that runs automatically when a condition is met
Advantages of Triggers
- It will examine the data and make changes if necessary
- Automate repetitive or complex tasks
- Improves efficiency
- Saving time
What is Concurrency control and why is it important?
- Ensures that correct and consistent behaviour when multiple transactions are executed concurrently in a multi-user environment
- Usually happens when multiple users try to write data at the same time or when one write and the other read
- Without proper control this concurrent access can lead to data inconsistency, lost updates and anomalies
- To ensure data integrity when updates occur to the database in a multi-user environment
Advantages of Semi-structured Data (XQuery) over traditional structured data (SQL)
- The data is not constrained by a fixed schema
- Data is portable
- Provides more flexibility in terms of data storage and management
- Scalability, well suited for managing large volumes of data
- Richer data analysis, contains more contextual information, such as metadata or tags. This provides additional insights and context that can approve the accuracy and relevance of data analysis
ACID transaction
- Atomic
All the operations within the transaction are completed successfully or none of the are - Consistent
Database constraints preserved.
The database remains in a consistent state before and after the transaction - Isolated
It appears to the user as if only one process executes at a time
Ensures that the intermediate state of the transaction is invisible to other concurrent transactions until it is committed - Durable
Effects of a process survive a crash
Once a transaction is committed, the changes made by the transaction are permanent and will not be lost, even in the event of a system failure
Why do we need Normalisation?
- The main reason for normalizing the relations is for removing anomalies.
- Failure to eliminate anomalies lead to data redundancy and can cause data integrity and other problems as the database grows.
- We want the database to be accessed and used by any user, data needs to be connected so that it can be joined, or linked, and so that changes to one piece of data automatically propagate throughout the system
Advantages of Normalisation
- Helps to minimize data redundancy
- Greater overall database organization
- Data consistency within the database
- Much more flexible database design
- Enforces the concept of relational integrity
- Protected from
insertion anomalies
deletion anomalies
update anonalies