Course

Basic Setup

What is SQL?

In this module- we'll learn the basics of SQL.

SQL stands for Structured Query Language. It's a special language that we use to talk to databases. Just like how we use different languages to communicate with people from different countries, SQL is the language we use to communicate with databases.

Giving Instructions to Databases

Imagine you have a big library with lots of books. The database is like that library, and the data inside the database is like the books. SQL is like the language you use to tell the librarian what books you want to find, add, or remove from the library. With SQL, you can give the database different instructions, such as:

  • Find all the books written by a specific author.
  • Add a new book to the library.
  • Remove a book from the library.
  • Update the information about a book.

Retrieving Information

One of the most common things we use SQL for is to get information from a database. It's like asking the librarian to find a specific book or a group of books based on certain rules. For example, you could say, "Find all the books about dinosaurs that were published in the last 5 years." The database would then look through all its data and give you back the books that match your request.

SQL Commands

SQL has different commands that you use to give instructions to the database. Some of the most basic commands are:

SELECT: Used to select data from a database. INSERT: Used to insert new data into a database. UPDATE: Used to modify existing data in a database. DELETE: Used to delete data from a database.

These commands are like the basic words you need to know to start talking to databases.

Why SQL is Important

Just like how knowing the right language helps you communicate with people, knowing SQL helps you communicate with databases. It's an important skill for anyone who wants to work with data, like programmers, data analysts, and data scientists. SQL helps you retrieve, update, and organize data in databases, making it easier to find the information you need and make better decisions.

Testing our Databases

In order to build databases and get a fundamental understanding of what's happening behind the scenes when we run code that manipulates our database: it's important you follow along.

For now we're just going over broad strokes and ideas- so we'll be building test databases locally.

Later, we'll discuss hosting databases on a service like Supabase or with MongoDB.

To begin testing- I would recommend using one of two options:

Method 1

A premade environment for testing/writing SQL such as DB Fiddle

This is a website with everything setup for you. You can hop right in and begin writing SQL code in a test environment without any setup.

Simply go to the website, make sure to select the right version of MySQL.

Image

All the code I will write here is using the syntax MySQL expects. MySQL is the most popular database. Different version of SQL like PostgresSQL will have a slightly different syntax- but the fundamentals will always be the same.

Now you can simply add your code to the left text-box to run SQL that will describe your table. And add code to the right text-box to write your queries. Pressing 'run' will execute all of the code.

Image

Method 2

Running a local MySQL server.

Prisma has a very in depth guide on the initial setup and I would recommend following their instructions for the setup Setting up MySQL on Windows Setting up MySQL on MacOS Setting up MySQL on Linux

Follow the instructions on the installer- but just setup a 'development' version. That will reduce the resources used by the server, instead of setting it up to handle and work as a real server used by hundreds and thousands of users.

Image

Your password is going to just be used locally. We won't be hosting any applications with this server so just choose a password you can remember.

We can run all of our tests on the 'root' user, so you won't need to make any extra user accounts.

Image

Once it's installed- you should be able to open a terminal and run access your server.

mysql -u root -p
Image

Once logged in- you'll need to create your initial Database to begin creating tables on it.

Image

You can now run SQL Directly in the CLI.

Image
Image
Insight

To Delete a table from a mysql database, just run 'DROP TABLE table_name' i.e.

DROP TABLE Users;

0 Comments

"Please login to view comments"

glass-bbok

Join the Conversation!

Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.

Upgrade your account
tick-guideNext Lesson

Creating a Table in SQL