In this lesson, you will learn how to bridge the gap between real-world business objects and database tables by defining Entities and Attributes.
What is an Entity?
An entity represents a distinct "thing" or object in your business domain that you want to store information about. In a database, an entity usually becomes a table. Think of it as the answer to the question, "What are we tracking?"
For a retail store, examples of entities would be Customer, Product, or Order. Each of these represents a collection of similar items that we want to keep track of systematically.
What is an Attribute?
An attribute is a specific piece of information that describes an entity. If the entity is the "what," the attributes are the "details." In a database table, these will eventually become your columns.
For example, if your entity is Customer, you might want to know their name, email address, and phone number. In this case, Name, Email, and Phone are the attributes of the Customer entity.
A Concrete Illustration
Let’s look at how we might model a simple Product entity for a store:
Entity: Product
- Attribute 1:
Product_ID(to uniquely identify it) - Attribute 2:
Name - Attribute 3:
Price - Attribute 4:
Stock_Quantity
When we translate this into a table structure, it looks like this:
-- Conceptual structure for the Product entity
CREATE TABLE Product (
Product_ID INT,
Name VARCHAR(100),
Price DECIMAL(10, 2),
Stock_Quantity INT
);
By identifying the entities first, you decide what you are tracking. By choosing the right attributes, you decide what details matter for each of those objects. You don’t need to record every possible fact about an object—only the attributes that help you run your business effectively.
Key Takeaway: Entities are the "things" you want to track (the tables), and attributes are the descriptive "details" of those things (the columns).