- Data
- Store in a file.
- Data Type Source
- Data basically come into database two ways
- Raw Data (From variable or constant)
- Form Data (may have file Data)
- Data Model
- When client's idea stored in mySql server (Idea ->structure model->table model->database).
- Query Standard
- Query select data which are required. Extract unnecessary data is very bad practice.
- Related Data
- In a same table column's (fields) do not have any other's table data. Like employee table have't any department information.
- Table
- Table have rows and columns like spreadsheet. Tables are used for store data.
- Column value contain single value with same data type.
- Cautions
- Similar data with many tables
- Related data are not allowed.
- Combination of value in a single row. Like, multiple value or comma separated values in a single row. Puzzle primary key. Atomic property reqired.
- Fuzzy column or table name.
- Poor planning and normalization.
- Relational Database
- Proposed 1069 by Edgar Codd (of IBM Research).
- When data cross another table through reference.
- MySql
- Created 1995 by Michael Widenius.
- MySql engine helps to store, handle, manipulate and retrieve data.
- InnoDB is default and major storage engine.
- mysql>show engine shows MySql engines. SET default_storage_engine = MYISLAM command for set default storage engine.
- Different engine have different capability like speed, storage, data integrity ...
- Data Types
- Category
- Numeric
- String
- Date
- Structure
- Signed
- Unsigned -only positive and long range
- Functional Dependency
- If the column value references another column value in a same table/another table is called functional dependency.
- Column student_name depends on student_id column because student_id column used to uniquely determine student_name.
- Non-key field
- Column value directly depend on primary key. On the other hand, column value partially or compositely depend on primary key is non-key field.
- Relation Among Tables
- One-to-Many
- Example 1 : In a 'student management' database one student can take one or more course but course is taken not more one student.
- Example 2: In a 'civil engineer' database one engineer can have one or more than one construction project but construction project is taken by one engineer.
- Many-to-Many
- Example : In a 'Library' database author have zero or more books but one book have one or more author.
- Junction Table: To support many-to-many relation demand to create a third table.
- One-to-One
- In a 'student management' database student postal code refer another address table is one-to-one relationship.
- Atomic Property
- When table contain single value instead multiple value.
- Normalization
- Divide larger table into smaller table with relational dependency. One table makes relation with other table.
- Benefits of Normalization
- Minimize redundant data, but no information loss
- Minimize dependency, improve business logic and figure related data, but no unusual data
- Minimize null value
- 1NF
- No repeat or duplicate column value. Atomic data.
- No related data (5).
- Row defined by Primary key and no repeated row.
- Contain/create primary key.
- 2NF
- Non-key field must depend on the primary key
- Should be in 1NF first.
After 2NF
- 3NF
- Should be in 2NF first.
- Every non-field attribute can't depend on non-field attribute. Ensure primary key on every non-field attribute.
- Example: Address attributes make a new table; zip code can be a primary key.
- Database Design
- Purpose of the Database
- Analysis Data
- Organize tables
- Determine fields
- Specify primary key
- Relation with other table
- Normalization
- Add Integrity constraint
No comments:
Post a Comment