Com 312 (Database Design)
Com 312 (Database Design)
Data models are foundational structures that define how data is organized, stored, and
1. Entity: An entity is a real-world object or concept with identifiable attributes. For example,
2. Attributes: Attributes are the properties or characteristics of entities. Each entity has
attributes that describe it. For instance, a student entity might have attributes such as student
3. Relationships: Relationships define how entities are connected or related to each other.
example, a student entity may have a relationship with a course entity indicating enrollment.
4. Keys: Keys are unique identifiers within an entity that distinguish each instance of the
entity. There are different types of keys, such as primary keys (which uniquely identify each
record in a table) and foreign keys (which establish relationships between tables).
5. Data Types: Data types define the kind of data that can be stored in an attribute. Common
data types include integers, strings, dates, and floating-point numbers. The choice of data
type depends on the nature of the attribute and the requirements of the system.
6. Normalization: Normalization is the process of organizing data to minimize redundancy
and dependency. It involves breaking down large tables into smaller ones and establishing
relationships between them to ensure data integrity and optimize database performance.
1. Hierarchical data model: These organizes data in a tree-like structure where each record
(or entity) has a single parent record and zero or more child records, forming a hierarchy.
Example: Consider a company's organizational structure, where each department has multiple
employees. The hierarchical model would represent this as a tree structure, with the company
as the root, departments as intermediate nodes, and employees as leaf nodes. Each department
would have employees as children, and each employee would have a department as its parent.
2. Network data model: This is a type of database model that extends the hierarchical model
by allowing each record to have multiple parent and child records, creating a network-like
structure.
Example: Consider a university database where students enroll in multiple courses, and each
course can have multiple instructors. In the network model, students, courses, and instructors
would be represented as sets, with records representing individual students, courses, and
instructors. Each student record could be linked to multiple course records, and each course
3. Relational data model: This is a type of database model based on the mathematical concept
Example: Consider a university database in the relational model. It might consist of tables
such as Students, Courses, and Enrollments. The Students table would contain student
information with a primary key like Student ID. The Courses table would contain course
information with a primary key like Course ID. The Enrollments table would establish a
many-to-many relationship between students and courses using foreign keys, such as Student
maintaining databases. Their duties include installing, configuring, and upgrading database
software, ensuring data security, optimizing database performance, backing up and restoring
2. Database User: A database user is an individual or program that interacts with a database
to perform various operations such as querying, updating, or deleting data. Users can have
different levels of access rights and permissions based on their roles and responsibilities
communicate with and manipulate databases. Examples include SQL (Structured Query
Language), which is used for querying and managing relational databases, and NoSQL query
languages like MongoDB's query language, which is used for working with non-relational
databases.
4. Data View: A data view is a virtual representation of data from one or more tables in a
database. It presents a subset of the data in a customized format that may include specific
columns, rows, or calculations. Data views are useful for simplifying complex data structures,
the actual data stored in the database, including all records, tables, relationships, and
6. Schema: A schema, on the other hand, is the overall structure or blueprint of the database.
It defines the organization of data, including the tables, fields, data types, relationships, and
constraints. The schema provides a framework for how data is stored and accessed within the
database, but it does not contain the actual data itself. It's like a plan or template for how the
1. Poorly defined requirements: If the requirements for the database are not clear or are
constantly changing, it can lead to a design that doesn't meet the needs of the users or the
application.
2. Denormalization: While denormalization can improve query performance, it can also lead
3. Overly complex schema: Creating a database with too many tables, relationships, or
4. Lack of indexes: Not properly indexing the database can lead to slow query performance,
5. Ignoring normalization rules: Failing to properly normalize the database can result in data
key, foreign key, unique constraints, and check constraints can lead to data inconsistencies
and errors.
7. Inadequate error handling: Not implementing proper error handling mechanisms can lead
9. Not considering security: Failing to implement proper security measures such as access
controls, encryption, and authentication can lead to data breaches and unauthorized access.
10. Inefficient querying: Writing inefficient queries or not optimizing queries can lead to
By avoiding these pitfalls and following best practices in relational database design, you can
SQL BACKGROUND
SQL, which stands for Structured Query Language, is a domain-specific language used in
programming and managing relational databases. It was initially developed by IBM in the
early 1970s as a way to interact with their databases. However, SQL as we know it today was
largely standardized by ANSI (American National Standards Institute) in the late 1980s and
The main purpose of SQL is to manage and manipulate data stored in a relational database
querying data, inserting, updating, and deleting records, creating and modifying database
databases, and it is supported by virtually all major database management systems, including
MySQL, PostgreSQL, Oracle Database, Microsoft SQL Server, SQLite, and many others. Its
versatility and widespread adoption have made it an essential skill for database
administrators, developers, data analysts, and other professionals working with data.
1. Keywords: These are reserved words used to perform specific operations in SQL, such as
2. Clauses: SQL statements are typically composed of one or more clauses, each serving a
specific purpose. Common clauses include SELECT, FROM, WHERE, GROUP BY,
3. Expressions: These are combinations of literals, column names, operators, and functions
that produce scalar values. Expressions are used in various parts of SQL statements, such as
4. Identifiers: These are names given to database objects such as tables, columns, indexes,
views, etc. Identifiers need to follow certain naming rules and conventions, and they are often
5. Comments: SQL allows for comments to be included in the code to improve readability
and provide explanations. Comments can be either single-line (using --) or multi-line