A List of PostgreSQL Commands for Beginners
Building a Mario Relational Database on freeCodeCamp

Search for a command to run...
Building a Mario Relational Database on freeCodeCamp

No comments yet. Be the first to comment.
In this series, I will document my progress through and impressions on freeCodeCamp's Relational Database certificate.
From Learn SQL by Building a Student Database Part 2
Two ways to make pop-up images in a Google Sheet

Since last we spoke Iβve been recording several new long and short form videos. Check out the YouTube Channel if you havenβt. Iβve also wrapped up training for a marathon Iβll be racing on March 3rdβ¦ π€π€ Now to the sheetsβ¦ Do you ever feel lost in E...

Originally published for freeCodeCamp In this article I will show you how to allow for multiple items to be selected using the drop-down data validation feature in Google Sheets. Here's the Google Sheet we'll use for the example. You can make a copy...

Originally published for freeCodeCamp Without clean data, your spreadsheet is knocking on death's door. In this tutorial, I will show you two fast ways to clean up the data in your Excel or Google Sheets spreadsheet. When dealing with data sets, esp...

Originally published for freeCodeCamp In this article I will show you how to format cells in Microsoft Excel. We'll be looking particularly at the Accounting format for cells with numbers. At the end of the article I'll give you two bonuses: a short...

I've dabbled with SQL a couple times, but never truly dove all the way in. I took Google's Data Analytics certification last year, and it gave a nice cursory overview of SQL, Big Query, Tableau and the R language. But, I'm ready to sink my teeth into understanding how to use PostgreSQL out in the wild.
I'm firing up this certification now, and I'm encouraged that it will be more impactful. Everything I've done on freeCodeCamp has been focused on learning through building. The projects are extensions of the lessons that make you actually have to re-learn what you've just been over in order to complete.
The browser version is in beta still, but I had significant issues on my PC when I tried to go through the earlier version solely through VS Code. I'm stoked to be starting now.
I've already been through the introduction to Bash section which was a nice overview of navigating the command line. If you're familiar at all with this type stuff, it won't take you longer than 20-30 mins to complete.
After completing 70% of the project, I encountered issues logging back in to finish it. I've had to delete the container and start from scratch. If you work on this certificate while it's in Beta, I recommend leaving each project open in your browser from start to finish.

I'm having to adjust to using the backslash
\rather than the forward slash/for these commands
CREATE DATABASE your_db_name; = yes, this indeed creates a new database πDROP DATABASE your_db_name; = delete your_db_name.\l = lists the databases

\c your_db_name = connects to a your_db_name databasesecond_database in the screenshot below:

\d: display the tables in the database you're currently connected to.

\d your_table_name: displays the details of your_table_name 
CREATE TABLE your_table_name(): yep, create a table
DROP TABLE your_table_name: deletes the tableALTER TABLE table_name ADD COLUMN column_name DATATYPE;: creates a new column in your tableALTER TABLE table_name DROP COLUMN column_name: removes a columnALTER TABLE table_name RENAME COLUMN old_name TO new_name: renames a column.ALTER DATABASE database_name RENAME TO new_database_name: renames database.INSERT INTO table_name(column_1,column_2...) VALUES(value_1, value_2...): insert the data via rows into the tables.

SELECT column(s) FROM table_name;: view data in table. (use an * between SELECT and FROM to select all the columns)

DELETE FROM table_name WHERE condition: deletes a row where the condition is met. i.e. condition(username='Luigi')

UPDATE table_name SET row_to_update = new_value WHERE condition: update a value in a row.

SELECT columns FROM table_name ORDER BY column_name;: put stuff in proper order.ALTER TABLE table_name ADD PRIMARY KEY(column_name);: sets a primary key to one of the columns.ALTER TABLE table_name DROP CONSTRAINT constraint_name;: drop a constraint (like removing a primary key)ALTER TABLE table_name ALTER COLUMN column_name DROP CONSTRAINT constraint_name;: drop a constraint from a column in the table.ALTER TABLE table_name ADD COLUMN column_name DATATYPE REFERENCES referenced_table_name(referenced_column_name);: Holy Toledo! This is how you set a foreign key. So it links tables together. The column added links to the referenced column in the referenced table. ALTER TABLE table_name ADD FOREIGN KEY(key_name) REFERENCES referenced_table_name(referenced_column_name);: Add a foreign key after the fact instead of with the creation of the column.ALTER TABLE table_name ADD PRIMARY KEY(column1, column2);: Creates a composite foreign key from values from two columns.FULL JOIN: This is where some magic happens. The full command is here: SELECT columns FROM table_1 FULL JOIN table_2 ON table_1.primary_key_column = table_2.foreign_key_column;: This hooks up two columns that we previously linked via keys.This is awesome! Two previously separate tables are now joined:

π

Don't forget semicolons at the end of the lines.
VARCHAR(n): a short string consisting of n number of characters.SERIAL: an integer that automatically increments when rows are added. See pic example below. The character_id is automatically assigned a value when I add a row of data.

NUMERIC(4,1): decimal data type. In this example, it has up to four digits and one of them has to be to the right of the decimal. CREATE TABLE table_name(column_name DATATYPE CONSTRAINTS): a one-liner to create a table with column and constraints.I honestly had a blast going through the basics of PostgreSQL in this little project. Looking forward to continuing with more of the Relational Database Certificate on freeCodeCamp.
Thanks for reading; you can find me over on Twitter, and I'd love if you said hey! π
Have a great one! π