After setting up your PostgreSQL environment in Chapter 1, you're ready to delve into the nitty-gritty.
When it comes to databases, especially in PostgreSQL, as we've begun exploring in Chapter 1, the basic building blocks are tables, rows, and columns.
To truly grasp these concepts, we'll break them down one by one.
A table is a collection of related data organized within a database. Think of a table as a neatly structured grid, like a spreadsheet. It's a space where you can store information about a specific topic, such as employees in a company.
In our ongoing exploration, we're working with an employees
table. This table is designed to hold all the information about employees in a particular organization.
An employee table inside PostgreSQL
Columns in a table define what kind of information will be stored. Each column has a unique name and a specific data type, which sets the rules for the data that can be stored in that column.
In the employees
table, here are some of the columns:
id
: The unique identifier for each employee.first_name
: The first name of the employee.gender
: The gender of the employee.start_date
: The date the employee started working.CREATE TABLE employees (
id VARCHAR(21) PRIMARY KEY,
first_name VARCHAR(50),
gender VARCHAR(10),
start_date DATE,
...
);
These columns provide structure and enforce consistency within the data.
A column in a table