Basic Database Concepts

circular structures in the background with neon lights and a light beam on each side of them

Note: this page has been created with the use of AI. Please take caution, and note that the content of this page does not necessarily reflect the opinion of Cratecode.

To make the most of databases, we need to get a handle on some of the fundamental concepts that form their backbone. Trust me, the stuff we'll go through here will appear time and time again, so strap in!

Tables and Keys

First things first, a database is essentially a collection of tables. Tables are the heart of any database. Picture a table as a grid with rows and columns, like an Excel spreadsheet.

Rows represent records, whereas columns represent fields. Here's an example of a Users table:

User IDNameEmail
1John[email protected]
2Cindy[email protected]
3Jim[email protected]

The User ID column is a special kind of column called a primary key. Each record (row) in a table must have a unique primary key. It's like the ID number at school or your Social Security number - no two are the same!

Queries

Now, moving onto the fun part - interacting with the data. How do we pull data out, put data in, or change existing data? Meet SQL queries - your new best friend.

SELECT * FROM Users WHERE Name ='John'

This query will return all records from the Users table where the Name is 'John'. The * is a wildcard that stands for 'all columns'. If you just wanted the email, you'd replace * with Email:

SELECT Email FROM Users WHERE Name ='John'

And that's just the tip of the iceberg! With queries, you can insert new records, update existing ones, and even delete records (use this one with caution!).

Hey there! Want to learn more? Cratecode is an online learning platform that lets you forge your own path. Click here to check out a lesson: Basic Concepts (psst, it's free!).

FAQ

What is a table in a database?

A table in a database is like an Excel spreadsheet. It's a grid that houses your data. Rows in the table represent records, while columns represent the fields of the records.

What is a primary key in a database?

A primary key is a unique identifier for each record in a table. It's like your ID number in school or your social security number - no two are the same!

What does the `*` mean in a SQL query?

The * in a SQL query is a wildcard that stands for 'all columns'. When you write SELECT * FROM Users, it means 'get all columns from the Users table'. If you only wanted the email addresses, you'd replace * with Email, like so: SELECT Email FROM Users.

Similar Articles