Difference between Entity and Attribute – The Crazy Programmer

In this article, we will have a look at the difference between Entity and Attribute, which form the core principles of the Entity-Relationship Model in Database Management System. We will look at the description of each in detail with examples and compare them for a clear idea.EntityAn Entity is defined as any object which has a real-time existence. Moreover, an object is only considered as an Entity if it is easily identifiable among all other objects. In the context of DBMS an entity typically represents data in an RDBMS. It is an object about which we store or retrieve data from the database. Now, the entities that share the same set of properties coalesce into an Entity Set.We represent an entity set as a relation or a table in Relational Database Management System. So, Each row in a table represents an entity and the table itself represents an entity set. Therefore, to maintain integrity and avoid ambiguity, it is essential that all entities (rows) are unique and must not be replicas of each other.Entity TypesThere are in general two types of entities:Strong Entity: A Strong Entity is an entity that does not depend on another entity. In the context of RDBMS, a Strong Entity contains the Primary Key of the Table. In ER Model we represent a Strong Entity via a Rectangular box.Weak Entity: A Weak Entity is one that always depends on another entity or parent entity. Hence, it has no Primary Key to uniquely identify it in the table. A doubly rectangular box usually represents a Weak Entity in ER Model.Now, let us understand the above-discussed points with some examples.Suppose we have a table Student which contains the following records:STUDENT_IDROLL_NOSTUDENT_NAMEADMISSION_YEARCONTACT_NODATE_OF_BIRTH1011Sean Wright201798674355731999/10/201022Ken Wilson201835465875562000/11/191033Robert Harris201864765856482000/03/07Explanation:Here each record in the Student Table represents a Student Object or Entity which exists in real-time. All the records together represent an Entity Set i.e Student Table. So, we see there are 3 entities in the above table. We see for the Student Entities with names ‘Ken’ and ‘Robert’ the ADMISSION_YEAR is the same but they are uniquely identifiable because of their STUDENT_ID and ROLL_NO. Hence, this makes the Student Table a Strong Entity Set.Now, a Weak Entity is dependent on another entity. So in databases, we represent weak entities that reference other tables or parent tables. In simpler terms, a weak entity has a key that refers to the primary key of another table to exist. Such keys are called Foreign Key.AttributeAn attribute describes the characteristics or properties of an entity. Like all entities combine to form an Entity Set, similarly a fixed set of attributes combining define an entity type. For each entity, certain properties describe them and even help to uniquely identify the entities. For Example, In the above Student Table, each column or value like the STUDENT_ID, ROLL_NO, STUDENT_NAME, etc are the attributes that define each Student Entity. Each attribute in a table accepts a set of values over a certain domain. In an entity, each attribute is allowed to have only one value which could be a number, text, date, etc. (defined in respective SQL Database Server )In simpler terms, every column header in a table is an Attribute.Attribute TypesHence, there are different types of attributes that define an entity:Simple Attribute: This attribute cannot be divided any further into its subtypes. These attributes can contain Null values. Ex: In the above table, STUDENT_ID and ROLL_NO are simple attributes.Composite Attribute: Composite Attributes are a combination of more than one attribute or simple attributes. Ex: In the Student Table the STUDENT_NAME Column can be subdivided consisting – FIRST_NAME, MIDDLE_NAME, LAST_NAME that can collectively form a name of Student. Similarly, there can be an Address Column for a Composite Attribute having City, Street, and PinCode Columns.Single Valued Attribute: These attributes allow only one or a single value. These attributes are different from Simple Attributes and usually form the key or Primary Key which uniquely identifies an entity. For an entity, there cannot be multiple values for this column or attribute. For Ex: STUDENT_ID and ROLL_NO are unique and Single Valued attributes in Student Table.Multi-Valued Attribute: These attributes can contain more than one value at a time. It can be a composite attribute. Ex: The CONTACT_NO Column in Student Table has only one value for each entity, but it can be Multi-Valued as a student can have more than one Contact Number.Derived Attribute: The derived attribute are those attributes that may or may not exist in the physical database. Its value gets derived from other attributes, or we can say that it depends on other database attributes for the data. Ex: In the Student Table we have Column DATE_OF_BIRTH through which we can derive an Attribute AGE by getting the current date. So AGE can be an example of a Derived Attribute. distinguishDifference between Entity and AttributeNow, let’s summarize the key differences between an Entity and an Attribute.Criteria SpecificationEntityAttributeDefinitionIt is a distinguishable object having a real-time existence.It is the property that defines the elementary structure of an entity type.ER Model RepresentationIn ER Model we represent an entity in a Rectangular Box.In ER Model we represent an Attribute in an Oval Bounded Region.Table RepresentationEach row or record in a table is treated as an entity.Here, each column header defines an attribute.TypesEntities are generally of two types: Strong Entity and Weak Entity.Attributes are generally of 5 types: Simple, Composite, Single-Valued, Multi-Valued, Derived.UseA group of entities defines an Entity set, represented in the database using tables.A group of attributes identifies an entity and usually forms the Key in the table.FunctionalityEntities represent the main objects of the RDBMS.Attributes represent the characteristics or standards to define an entity.So, that’s all about the article we had a detailed look at each topic and summarized the key differences between them.You can leave your suggestions/doubts in the comment section below.

Coded at

Share your love

Leave a Reply