Setting Up Our Database for the Course Project
In this course, you will take on the role of a data analyst working for a company. Your task is to analyze and manage a database for the company, named Green Cycles. In this lesson, we will set up the database, load the necessary data, and execute our first SQL query.
Step 1: Open pgAdmin
- Search for pgAdmin in your system and open it.
- Maximize the window for better visibility.
Step 2: Create a New Database
- In the pgAdmin interface, expand the latest PostgreSQL version under Servers.
- Locate the Databases section, right-click on it, and select Create Database.
- Name the database Green Cycles.
- Click Save.
Now, your database is created! 🎉
Step 3: Check the Schema and Tables
- Expand Schemas under the Green Cycles database.
- You will see a default schema named public.
- Expand Tables—currently, there are no tables in the database.
Step 4: Load Data into the Database
To add data, we will execute a SQL script file that contains all necessary commands to create tables and insert records.
Steps to Load the Data:
- Download the SQL file provided in the course materials.
- Extract the file from the downloaded folder.
- Locate the SQL file inside the extracted folder.
- Copy the folder path where the SQL file is located.
Step 5: Execute the SQL File in pgAdmin
- In pgAdmin, open the Query Tool:
- Right-click on Schemas → public.
- Select Query Tool.
- Click on the Open File icon.
- Paste the folder path where the SQL file is located.
- Select the SQL file and click Open.
- Click on the Play button (â–¶) or press F5 to execute the script.
Once executed, you should see a message: Query returned successfully.
Step 6: Refresh the Database
- Right-click on Schemas → public and select Refresh.
- Expand Tables, and you will now see multiple tables created in the database.
Step 7: Run Your First SQL Query
Now, let’s run a simple query to see if our data was loaded correctly.
-
Open the Query Tool again.
-
Delete any existing text.
-
Enter the following SQL command:
SELECT * FROM public.actor; -
Press F5 or click the Play button (â–¶).
You should now see a table displaying the actor data from the public schema. 🎉
Next Steps
Now that our database is set up, we will introduce the course project in the next session. You will begin analyzing and managing the data for Green Cycles using SQL queries. 🚀