What is a Database?
Think of a database as a digital filing cabinet where you can store and organize vast amounts of information. It's like a collection of spreadsheets, but much more powerful and organized.
Why Do We Need Databases?
Imagine you're running a business and you need to keep track of your customers, orders, and inventory. It would be a mess to handle all this information on paper. Databases make it easy to store, retrieve, and manipulate this data efficiently.
A database is made up of tables. Tables are like virtual spreadsheets with rows and columns. Each row represents a record, and each column represents a different piece of information about that record.
Example Table: Customers
CustomerID | Name | Age | |
---|---|---|---|
1 | John Smith | 30 | john@example.com |
2 | Jane Doe | 25 | jane@example.com |
3 | Alex Brown | 28 | alex@example.com |
Each row in a table is called a record. Going back to our "Customers" table example, each row represents information about a specific customer.
Columns in a table are called fields. Each field holds a specific type of information. For instance, in the "Customers" table, "Name," "Age," and "Email" are fields.
Every table should have a primary key. This is a unique identifier for each record in the table. In our "Customers" table, "CustomerID" serves as the primary key.
In the real world, data is often connected. For instance, customers make orders. Databases allow us to establish relationships between tables to represent these connections.
Example Table: Orders
OrderID | CustomerID | Product | Quantity |
---|---|---|---|
101 | 1 | Widget A | 2 |
102 | 2 | Widget B | 5 |
103 | 1 | Widget C | 1 |
Here, the "CustomerID" field in the "Orders" table establishes a relationship with the "Customers" table.