Introduction to Database Design (Coding Bootcamp series)
As I approach the end of my programming bootcamp at Green Fox Academy, I bring you something I have not mentioned yet but that is essential for any backend programmer: databases and relationships.
A database is a collection of tables, with each of them containing data about a different, but related subject. A table is composed of records and fields that contain data. Each row in a table is a record and each column is a field of that record.
In a relational database — one where data is related to other information across databases — it is necessary to uniquely identify each record on a table. That is achieved through the use of a Primary Key. A Primary Key is a column, or combination of columns, that is unique to each record and cannot contain null values, allowing each record to be properly identified. A Primary Key can be a String (example: an email address) or, as in most cases, a number, most likely a Long. In the latter case, this can be auto-generated, leaving out the worry to the developer to create a unique ID for each record. For that, we would do something like this (example taken from our project):
Also, notice the @Entity annotation. It is a specialisation of the @Component annotation, informing that this class is an Entity, that is, a table in the database.