Database
A database is an organized collection of data stored electronically. It can store text, numbers, pictures, videos, and files. A software used to manage databases is called DBMS.
Data and Information
Data: Raw facts without meaning. Example: numbers, symbols.
Information: Processed data that has meaning.
Database and DBMS
Database: Collection of logically related data stored in organized form.
DBMS: Software used to create, update, and retrieve data.
Examples: LibreOffice Base, MS Access, Oracle, MySQL
Advantages of DBMS
- Organized storage
- Fast retrieval
- Data sharing
- Minimal data redundancy
- Data consistency
- Efficiency
- Accuracy
- Data validity
- Security
Data Models
A data model defines how data is stored and related in a database.
- Hierarchical Model
- Network Model
- Relational Model
Hierarchical Model
Data is arranged like a tree structure with parent-child relationships.
Network Model
A child can have multiple parents. More flexible than hierarchical.
Relational Model
Data is stored in tables and connected using common fields. Given by E. F. Codd in 1970.
Relational Database Terminology
- Entity: Real-world object (student, teacher)
- Table: Collection of records in structured format consisting of rows and columns.
- Field or column or attribute: It is the smallest entity in the database. It holds data values of one type only.
- Data values: Raw data represented in numeric, character or alphanumeric form.
- Record or row: It holds data values of all the fields for a single person or object in a table.
- Primary Key: Unique identifier
- Foreign Key: Connects tables
- Candidate Key: Possible primary keys
- Alternate Key: Candidate keys not selected
Objects in RDBMS
- In a DBMS, objects are structures used to store and manage data.
- These objects help in organizing, retrieving, and manipulating data efficiently.
Main Database Objects
1. Table
- Primary object in a database
- Stores data in rows and columns
- All data is stored inside tables
2. Forms
- Used to enter data easily
- User-friendly interface
- Contains text boxes, checkboxes, buttons, etc.
- Data entered through forms is stored in tables
3. Queries
- Used to retrieve, update, or manipulate data
- Helps to extract required information
- Example: SELECT * FROM Students
4. Reports
- Formatted and organized display of data
- Used to show meaningful information
- Helpful for analysis and decision-making
- Used for informational and presentation purposes
Data Types
Data type defines what type of data a field can store.
- Text
- Numeric
- Currency
- Date
- Boolean
- Binary
Text Data Types
- Text data is a combination of letters, numbers or special characters. No arithmetic calculations can be performed on text data.
- Memo – large text
- CHAR – fixed text
- VARCHAR – variable text
Numeric Data Types
Used for numbers and calculations: Integer, Decimal, Float, Double.
Currency Data Type
Stores money values.
Date Data Type
- Date
- Time
- Timestamp
Boolean Data Type
True/False or Yes/No values.
Binary Data Type
Stores images and sounds.
Creating Tables
Design View: Manual table creation
Wizard: Automatic table creation
Master vs Transaction Table
Master table stores main data. Transaction table stores activity data.
Relationships
Tables are connected using common fields.
Examples of Database Relationships
One-to-One Relationship
In a one-to-one relationship, one record in a table is related to only one record in another table.
Example:
- One student → One ID card
- One person → One passport
- One vehicle → One registration number
One-to-Many Relationship
In a one-to-many relationship, one record in a master table is related to multiple records in another table.
Example:
- One teacher → Many students
- One customer → Many orders
- One department → Many employees
Many-to-Many Relationship
In a many-to-many relationship, multiple records in one table are related to multiple records in another table.
Example:
- Many students ↔ Many subjects
- Many doctors ↔ Many patients
- Many authors ↔ Many books
Keys in Database
- Primary Key
- Composite Key
- Foreign Key
Query
A query retrieves data from database based on conditions.
Database Languages
DDL (Data Definition Language): used to define, modify, and manage the structure of database objects. CREATE, ALTER, DROP are some of the commands.
DML (Data Manipulation Language): used to manage, retrieve, and modify data within database tables. SELECT, INSERT, DELETE, UPDATE are some of the commands.
Comments
Post a Comment