Database Principles Flashcards
What is a surrogate key and when is it used
A single column that you fill with artificial values. Used when a table doesn’t have data that supports creating a natural primary key
What is a candidate key
A minimal super key that is, a key that does not contain a subset of attributes
What is an alternate key
A key that contains all the properties needed to become a candidate key. Can be a set of single attributes or multiple attribute
What is a superkey
A key that can uniquely identify any row in the table. Time attribute is a good example of a super key
Does the order of creation matter
Yes cant create an intersection table cust_order before table customer
What is DDL
- Data Definition Language (DDL)
Allows the DBA or users to describe and name entities, attributes and relationships required for the applications that access it
Examples
CREATE TABLE, ALTER TABLE, DROP TABLE, RENAME TABLE
What is DML
- Data Manipulation Language (DML)
Provides the ability to manipulate data within the database.
Examples
SELECT, INSERT, UPDATE, DELETE
What is a join and how does it work
A JOIN links tables by selecting only the rows with common values in their common
How does inner join work
Only returns matched records from the tables that are being joined
How does outer join work
Matched pairs would be retained, and any unmatched values in the other table would be left NULL
What is data control language
Language used to control access to data stored in a database
Example
REVOKE
GRANT
What is a transaction
Any request for a piece of information from a database
What is transaction analysis
the process of ensuring that multiple database operations (like updates or inserts) are done correctly and completely as a single
What is the purpose of TA and what does it allow
- Purpose of transaction analysis is to be able to see which tables are used the most in transactions
- With this information we can optimize the tables
It guarantees data consistency and reliability
. Can help identify problems
. can improve performance
What are the 3 main categories of databases
○ According to the number of users
○ According to the type of use
○ According to Database site location
What are 2 categories for users in a database
Single User database systems
Multi User database systems
What is a Single User database systems
. Database is on the PC and hard disk
. All applications run on the same PC and directly access the database
. A single user accesses the application
What is a Multiuser database systems
. many PC’s connected through a LAN
. a file server stores a copy of the database files
. each user runs a copy of the same application and accesses the same files.
What are the 4 categories for type of use in a database
Production or Transactional Database system
Data Warehouse
Decision Support Database System
Research
What is Production or Transactional Database system
. Used for management of supply chain and for tracking production of items in factories, inventories of items in warehouses/stores and orders for items
. Used for purchases on credit cards and generation of monthly statements
. Used in Banks for customer information, accounts, loans and banking transaction
What is a data warehouse
. Historical collection of data and transaction
. Can be used to find trends
What is a Decision Support Database System
. Its a hybrid
. Aids users in judgement and choice activities
. Used in environments like business, health care and military where you have to make decisions
What are the 4 categories for database location
Centralised database system
Parallel database system
Distributed database system
Client/Server database system
What is a centralised database system
Single processor together with its associated data storage devices and other peripherals
What is a parallel database system
○ A database system implemented on a tightly coupled multiprocessor or on a loosely coupled multiprocessor
○ They link multiple smaller machines to achieve the same throughput as a single larger machine
What is a distributed database system
○ Data is spread across a variety of different databases
○ Managed by a variety of DBMS’s that are running on various types of machines having different operating systems
○ Each machine can have is own data and applications, and can access data stored on other machines
○ Each machine acts as a server as well as client
What is a client/server database system
○ Client-server technology instead of centralized system
○ There is a server which acts as a whole data base management system
Name some concurrency transaction problems
The lost update
The uncommitted dependency
The inconsistent analysis
What is the lost update
An apparently successfully completed update operation by one user can be overridden by another user
What is the uncommitted dependency
occurs when one transaction is allowed to see the intermediate results of another transaction before it has committed.
What is the inconsistent analysis
○ Occurs when a transaction reads several values from the database but a second transaction updates some of them during the execution of the first
○ For example, a transaction that is summarizing data in a database (for example, totalling balances) will obtain inaccurate results if, while it is executing, other transactions are updating the database
Name some transaction control techniques
Timestamping
Serializability
Locking
What is timestamping
○ A concurrency control protocol that orders transactions in such a way that older transactions, transactions with smaller timestamps, get priority in the event of conflict
○ A unique identifier created by the DBMS that indicates the relative starting time of a transaction
What is Serializability
○ Ensuring that a set of transactions in a database system produce the same results as if they were executed one after the other in some order, even though they may be executed concurrently.
What is locking
Prevents deadlock
○ A procedure used to control concurrent access to data. When one transaction is accessing the database, a lock may deny access to other transactions to prevent incorrect results.
○ Ensures serializability of concurrent transactions
§ Shared lock - If a transaction has a shared lock on a data item, it can read the item but not update it.
§ Exclusive Lock - If a transaction has an exclusive lock on a data item, it can both read and update the item.
What is a deadlock
A situation arises when two (or more) sessions are waiting to acquire a lock on a shared resource, and none of them can proceed because a second session also has a lock on some other resource that is required by the first session.
HAVE A LOOK AT RELATIONAL ALGEBRA
HAVE A LOOK AT RELATIONAL ALGEBRA
What are the 3 things we need to understand when starting a database
- Business rules
- Optimisation
- The correct data types
What do data types do
- This limits violations of data integrity
- Defines the kinds of values that can be used or stored
What do numeric data types do
Numeric data types allow us to specify the range of digits for specific values
What are the differences between char and varchar
- Char is fixed varchar is not
- They are stored on the disk differently
- Var char takes 2 bytes per character whereas char only takes 1
- Char saves more memory
What is one way we can optimise databases
Using less joins