views:

1032

answers:

8

Is it things like tables? Or would it also include things like constraints, stored procedures, packages, etc.?

I've looked around the internet, but finding elementary answers to elementary questions is sometimes a little difficult.

+1  A: 

it kind of depends how you think about it and how you model your problem domain. most of the time when you hear about entities, they are database tables (one or many) mapped onto object classes. So it's not really an entity until it's been queried for and turned into a class instance.

but again, it depends on your modeling methodology, and there are multiple :-)

Joel Martinez
+2  A: 

That's quite a general question!

Basically, all types that the database system itself offers, like NUMERIC, VARCHAR etc., or that the programming language of choice offers (int, string etc.) would be considered "atomic" data(base) types.

Anything that you - based on your program's or business' requirements - build from that, business objects and so forth, are entities.

Tables, constraints and so forth are database-internal objects needed to store and retrieve data, but those are general not considered "entities". The data stored in your tables, when retrieved and converted into an object, that then is an entity.

Marc

marc_s
I would agree with you. An "Entity" is usually the representation of a real world object. A PERSON table is the entity representing a real world person. Things like first name, last name, etc are Attributes of the entity.
Brett McCann
A: 

Update:

See this article in my blog in which I try to cover the subject in more detail:


An entity is a term from the entity-relationship model.

A relational model (your database schema) is one of the ways to implement the ER model.

Relational tables represent relations between simple types like integers and strings, which, in their turn, can represent everything: entities, attributes, relationships.

You cannot tell what is it only from the relational structure, you need to see the ER model.

For table persons,

id   name  surname
1    John  Smith

id, name and surname are entities in the real world and may or may not represent entities in the underlying ER model.

The fact of a record exists in the table means that these entities are in the following relation: "person 1 has name John and has surname Smith".

In the example above, the entity is defined by id (from the model's point of view).

If a person changes his name from John to Jack, the person remains the same (again, from the model's point of view), but gets related to another name.

In example above name and surname can be treated as attribute (as opposed to entity), but again, you need to see the ER model which this schema implements to tell what is it.

In some ER-to-relational model mappings, an entity should be defined in a table referenceable with a FOREIGN KEY to be considered an entity (which should constrain its domain).

However, this constraint can exist but not be represented in a database (due to technological limitations or something else).

Like, we cannot keep a list of all possible names, but the name of @#$^# is most probably a non-name, hence, it does not belong to the domain of names.

Therefore, an attribute is an entity which can participate in a relationship but cannot be contained in a domain-defining table.

For instance, the table prices:

good_id  price

defines relationships between the set of goods (which is defined by the table goods) and the set of real numbers (which cannot be contained in a table since it's not even countable).

Still each price (like $2.00) is a real-world entity just as well.

Quassnoi
aren't id, name and surname ATTRIBUTES rather than ENTITIES?
marc_s
In my understanding, this row representing one "Smith, John" as a WHOLE would be an entity
marc_s
`@marc_s`: patience!
Quassnoi
I would not consider id, name and surname as entities as they are incapable of independent existence, while a person as a whole is.
Adamski
`@Adamski:` so there is no such thing as name `John`?
Quassnoi
`@marc_s`: so if a person changes their name from 'John' to 'Jack' becomes another entity?
Quassnoi
@Quassnoi: In your example I would argue that John is an attribute: John cannot exist independently within your domain. If you had defined entities FirstName and LastName then it's arguable that John would be an entity.
Adamski
`@Adamski`: in some `RDBMS`'s you can define either a table with `3` rows (and make a `FOREIGN KEY` to it), or define an enumeration which will return you, say, `Red`, `Blue` or `Green` and nothing more. By your logic, color defined using he first method is an entity, color defined using the second method is not. Does the implementation method make color less on an entity?
Quassnoi
I think he was looking at the context of a database. John does not have a relationship to Smith. John without Smith is nothing but names. John Smith however is a person. A person is an entity and is represented in the database as a table.A table used to store the set of valid values is not an entity it is business logic, it is the physical model. If you looked at the logical model you should not see colors represented at all except as a field of an entity.
David
`@David`: yes, `John` and `Smith` are names, and they are related to person `1`. It's not `John Smith` that is person, it's a person that is person. The current technology does not (yet) allow using a `DNA` print as a `PRIMARY KEY`, that's why we use a surrogate key to define a person. If person `1` changes surname from 'Smith` to 'Jones`, it will remain the same person, but will no more be a `John Smith`. A table represents the `relations`, not `entities` (and in `PostgreSQL`, it's even called a `relation`). An entity is some value from a `domain`, which is completed defined by this value.
Quassnoi
@Quassnoi: no, if a person changes the name from John to Jack, it's still the same ENTITY, but with a different name ATTRIBUTE.
marc_s
`@marc_s`: so the whole row does not define an entity?
Quassnoi
+1  A: 

We'd need to know some context. One thing people sometimes do when analysing data in prepartion for designing a database is to create an Entity Realtionship Diagram, where you are considering what data items you are managing and their relationships.

I wonder if that's the context you mean?

If so perhaps a read of this article would get you started?

djna
+2  A: 

In the entity relationship world an entity is something that may exist independently and so there is often a one-to-one relationship between entities and database tables. However, this mapping is an implementation decision: For example, an ER diagram may contain three entities: Triangle, Square and Circle and these could potentially be modelled as a single table: Shape.

Also note that some database tables may represent relationships between entities.

Adamski
+1  A: 

This thread is demomnstrating one reason why it is difficult to find "elementary answers to elementary questions". Certain words have been used by different programming paradigms to mean different things (try asking a bunch of OO programmers what is the difference between a Class and an Object sometime).

Here's my take on it.

I first came across Entity as a modelling term in SSADM (ask your dad). In that context an Entity is used to model a logical clump of datas during the requirements gathering / analysis phase. The relationships between entities were modelled using the Entity Relationship diagrams, and the profile of an Enity was modelled using Entity Life Histories. ELH diagrams were very useful in COBOL systems but utterly horrible in relational databases. ERDs on the other hand continue to be useful to this day.

During the design and implementation phases the Entities get resolved into database tables, objects or records in a COBOL input file. In the course of that process a logical entity may get split across multiple tables, or several entities may get squidged into a single table, or there may be a one-to-one mapping. Sometimes an entity is resolved away entirely or lingers on as a view or a stored procedure.

APC
+1  A: 

This seems helpful: http://en.wikipedia.org/wiki/Entity-relationship%5Fmodel

In a database an entity is a table. The table represents whatever real world concept you are trying to model (person, transaction, event).

Contraints can represents relationships between entities. These would be foreign keys. They also enforce rules like first_name can not be blank (null). A transaction must have 1 or more items. An event must have a date time.

Stored Procedures / Packages / Triggers could handle more complex relationships and/or they can handle business rules, just depends on what it's doing.

David
+1  A: 

Entities are "things of significance" to the users/business/enterprise/problem domain.

ObiWanKenobi