Week 2 - Database Design
1.Advantages of relational database?
- Structural independence
Data needs storing once and independent of the application programs - Reduced data redundancy
Eliminate data anomalies - Increased Data Sharing
Many people can access the DBMS - Easy access
Ability to make ad hoc queries by using Structured Query Language (SQL) - Better security
Easy to provide varying access privileges - Easy to expand for future data growth by adding any tables
2.The role of PK
- To uniquely identify each row.
3.Rules to chose a Primary Key
- to be unique
- Consider all possibilities of data values
- Use the minimum number of columns if using combined columns.
- Has to be a stable value – not often changing
4.The role of FK
- Foreign key is useful to establish a relationship between two relations.
5.Rules to chose a Foreign Key
- An attribute or a combination of attributes in one table whose values must either match the primary key in another table or be NULL .
6.Difference between database and DBMS(database management system )
- A DBMS can contain one or more databases.
- Each database will communicate with the database management system (DBMS) to process the contents of the database tables.
7.Top-down design
<1>Identification of different entity types
<2>Definition of each entity’s attributes
即先建实体表再填充表里的内容
8.Bottom-up design
<1>Defines the attributes
<2>Groups them to form entities
9.Conceptual data model(概念数据模型) Logical data model(逻辑数据模型) Physical model(物理数据模型)
- 概念数据模型是现实世界到信息世界的第一层抽象,简单定义几个实体去体现他们之间的联系
- 逻辑数据模型是对概念数据模型进一步具体化,在概念数据模型定义实体的基础上定义了各个实体的属性
- 物理数据模型是在逻辑数据模型的基础上,综合考虑各种存储条件的限制,进行数据库的设计,从而真正实现数据在数据库中的存放。其主要的工作是根据逻辑数据模型中的实体、属性、联系转换成对应的物理模型中的元素,包括定义所有的表和列,定义外键以维持表之间的联系等
10.SQL( Structured Query Language)
SQL can be divide into 3 categories as DDL, DML or DCL
- DDL ( Data Definition Language)
SQL can be used to describe the logical, and sometimes physical, structure of a database (Create, Alter and Drop table commands) - DML (Data Manipulation Language)
SQL is used to access and modify the contents (data) of a database (Select, Insert, Update, and Delete commands)
Transaction control DML statements are Commit and Rollback - DCL (Data Control Language)
SQL is used to control access to data (Grant and Revoke commands)
Week 3 - Data Modelling
1.one-to-one (1:1)
解析:
这个是ER图的1:1表现。可见两边都是||。变红的那个是作为外键。
2.one-to-many (1:M)
解析:
||还代表1,那个分叉代表M。红色的为外键。
3.many–to–many(M:N)
解析:
1:M:N:1即实现M:N
4.Data dictionary
内容:
- The definitions for the data elements
- The composition of data - Each entity and its associate attributes
- Data kept
注意:
在Null(y/n)中,n表示不能为空,y表示可以为空。
Single Table Query
Multiple Table Query
---------------------------------- --------------------------------------------
Normalization
1.What is database Normalisation?
Normalisation is a process that involves arranging attributes in a relation, based on functional dependencies among the attributes.
2.Benefits of normalization
Normalisation results in reducing data redundancy and improving data integrity.
3.Normalisation process
- Top Down Modelling
Suitable for larger systems.
Identify entities, then relationships and attributes create a data model. - Bottom up Modelling(relational analysis)
Suitable for a small manageable system.
<1>Gathering all attributes concerned with a problem
<2>Creating one relation holding all attributes
<3>Applying the normalisation rules to this relation, breaking in down into smaller relations as duplications and dependencies
4.Full functional dependencies (FDD)
Attribute B is fully functionally dependent on composite attribute A, if is dependent on the whole of A, but not on any subset of A (说白了就是完全依赖于组合主键)
eg:
具体例题解析如下:
三范式
Physical Database Design
从分析数据到设计出物理数据库的的流程:
分开来看:
Logical database design:
1.Complete Logical data model
- There should be NO many-to-many relationships - introduce associative entities where appropriate.
- Add cardinality and optionality
- Both Primary Keys (PK) and Foreign Keys (FK) are to be shown.
2.Draw Relations
3.Normalse relations
Physical database design:
1.Tables in a relational database
2.Physical implementation
Logical to physical conversion
- Normalised relations in logical design becomes tables in the physical design (简单说就是将逻辑设计中的关系图具体化成数据库中的表)
- Each attribute in a relation becomes a field in the corresponding table in the database
- The conversion needs to pay attention to field names, descriptions, data types and size
Merging Relations(合并关系)
1.Synonyms(同义词可合并)
2.Homonyms(同音词不可合并)