Database tables

What is a Database Table?

A database table is a structured collection of related data entries organized in rows and columns. It is the fundamental building block of a database and is used to store and organize information.

Anatomy of a Table

A database table consists of the following components:

  1. Table Name: Each table is identified by a unique name which is used to refer to the table in queries and operations.

  2. Columns: Columns, also known as fields, define the different types of information or data points that can be stored in the table. Each column has a unique name and a specific data type, such as text, number, date, etc.

  3. Rows: Rows, also called records or tuples, represent individual entries or data instances within the table. Each row contains values or data corresponding to its respective column.

Creating a Table

To create a table in a database, you need to define the table schema specifying the column names, data types, and any constraints. Here’s an example of creating a simple table called Customers:

CREATE TABLE Customers (
    id INT PRIMARY KEY,
    name VARCHAR(100),
    email VARCHAR(255),
    age INT
);

In the above example, the Customers table has four columns - id, name, email, and age. The id column is defined as the primary key, which ensures unique values for each record.

Interacting with Tables

Once a table is created, you can perform various operations on it, such as inserting data, querying data, updating records, and deleting records. Here are some common SQL queries for interacting with tables:

Conclusion

Database tables are vital components for organizing and storing data in a structured manner. Understanding the anatomy of a table and how to interact with it using SQL queries is crucial for managing data effectively in databases.

#database #tables