I am new to SQL. I am confused between 'attribute' and a custom column we create with 'ALTER' . For Example:
ALTER TABLE table_name
ADD column_name datatype
Doesn't this 'column_name' be our new attribute in the table ?
A "Column" is a column in a database table whereas "attribute(s)" are externally visible facets of an object. An "attribute" is for a model and a "column" is for a table in a database. Here "retreats" is a table in a database with the following columns "title", "tagline", "created_at", "updated_at".
You can think of an attribute as a column in an entity table. An attribute value is the value used to describe a specific member.
The columns in a table is a field and is also referred to as an attribute. You can also think of it this way: an attribute is used to define the record and a record contains a set of attributes.
An attribute is simply one non-null cell in the spreadsheet, or the conjunction of a column and row. It stores only one piece of data about the object represented by the table in which the attribute belongs.
The confusion is due to a difference in the terminology we use for the logical "model" and the database implementation.
In the (logical) Entity Relationship Model (ERM), an "Entity" has "Attributes".
When we implement the model into a relational database, an "attribute" for an "entity" gets stored as a "column" in a "table".
In the (implemented) relational database, a "table" contains "columns".
We add attributes to entities; we add columns to tables.
(This relates to the standard relational model, and disregards any discussion of implementing an Entity-Attribute-Value (EAV) model in the database.)
For example:
ALTER TABLE order
ADD COLUMN date_received DATETIME ;
This is adding a column, with a column name of date_received
to the order
table.
We add the column, because in the logical model, the "Order" entity has an attribute of "date received".
The Entity-Relationship design discipline covers "entities" that have "attributes." The physical-level RDBMS design discipline covers "table" and "columns." An entity -- a person -- might have an attribute of "given name". The corresponding table would be called person
in an RDBMS, and it would have a column called given_name
.
Entities and columns are the same thing in slightly different kinds of jargon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With