SQL Tutorial for Beginners 1: Installing PostgreSQL and Creating Your First Database

Corey Schafer · Beginner ·📊 Data Analytics & Business Intelligence ·10y ago

Key Takeaways

This video tutorial covers the basics of setting up a PostgreSQL server and creating a first database, including installing PostgreSQL and a graphical interface program called PSequel, and creating a database using SQL commands.

Full Transcript

hey everybody how's it going in this video we'll be learning the basics of SQL queries from the ground up now SQL is a great language for programmers to learn because it's hard to find a software system these days that doesn't talk to some type of database on the back end and not only is it a great thing to know but it's also a good starting point for certain people who are interested in getting started in computer science because in my opinion it's not nearly as difficult as learning the ins and outs of a programming language like Python or JavaScript or Java I mean there are just a limited number of commands and for most jobs you're going to be using the basics of SQL such as grabbing values from a database that meet a certain criteria or something like that now there are times when more advanced queries are going to be needed but if you learn the basics then it's going to put you in a position where you can do the majority of the queries and then you can learn the more advanced stuff whenever you're ready so with that said let's go ahead and get started so in this video I'm going to show you how I set up my environment so that I can run SQL queries and also we're going to create our first database and connect to that database now for these tutorials I'm going to be using a Postgres database now I'm on a Mac so I'll show you the process that I went through to set this up on my machine so first we're gonna need to install Postgres and on the Mac the easiest way to do this is with the Postgres dot app now if you search in google here for Postgres Mac the first result is the official website and if we open up that website you can see that they have a downloader here but then they also recommend the Postgres app here as a simple native Mac app that runs in the menu bar without the need of an installer and that's what I think is the easiest so I already have that pulled up here but if you run the search it's the second result here this Postgres dot app so now that we're in this website we can just download like this like any other application so let's go ahead and run that download so now once that download is finished let's go ahead and unzip this and now let's go ahead and move this application over to our Applications folder so I've already got that pulled up here I'm gonna drag that on over okay now with that Postgres app installed that's going to give us a Postgres server that we can talk to using the command line now the command line isn't the best way to visualize what's going on so we're also going to want a graphical interface program to inspect our databases now on the Postgres app website that i had pulled up earlier they list a few of their favorite GUI tools here so I'm going to click on this link and these are some of the GUI tools that they recommend now the tool that I'm going to be using for these tutorials is this one down here near the bottom called P sequel now if you prefer another option then go ahead and use what you like but the reason that I chose this program is because it's very clean it has a simple layout and it also has the ability to enlarge fonts which a few of the other one surprisingly didn't have now these features are important to me because recording these videos I don't want a lot of windows and stuff getting in the way and also I want to make the font large enough for you guys to be able to see what I'm typing so let's go ahead and download this program just like we did the other one and then we're also going to move that to our Applications folder so let's go ahead and unzip this and I will open up Applications folder again and just drag this over here okay now with both of these programs installed let's first start our sequel server by Ronit up by running this Postgres app so now we can see that our server is running because if we look up here in the top menu we can see that this little elephant icon here and it says running on port 5 4 3 2 now it's also going to pop up this window here with this option to open P SQL and what that's going to do is it's going to open up the command line for us to start typing in commands now I know that the command line can be intimidating to some people but we're not going to be in here for long all we're gonna do is create a database that we can work with so to create this database it's just as simple as running the command create database and we're gonna call this sample underscore DB and we need to end this with a semicolon so let's go ahead and hit enter there and you can see that it says create database now there's a piece equal command here backslash L if we run that then we can view the databases that we have here and you can see that it created a few for us whenever we first installed the program but we can see here that we do have this sample underscore DB now to quit out of this command line we can do this backslash Q and it takes us back to our normal terminal so now I quit out of the command line there because we're not going to need to use it anymore because the command line it's not the prettiest way to see what's going on in our database so let's connect to the sample database that we just created using the P sequel application that we downloaded earlier so I'm going to go ahead and launch that now if you get this little error here cannot be opened because developer cannot be confirmed that's because I double clicked it's a weird thing with the Mac if you actually right click it and click open then it'll give you the option to override that and just open that up anyway now you'll see that with certain applications so now that we have this application opened up we're going to connect to our database and we're going to accept most of the defaults here you can see the port is 5 4 3 2 the same one that's listed whenever we right-click on our server it says it's running on port 5 4 3 2 the one thing that we are going to want to change here is that we're going to want to type in the database that we created so we called that sample underscore DB and now we can go ahead and connect to that database and we've successfully connected to the database now there's nothing here right now that's because we don't have any tables or any information within our database yet but we are in a position now to where we can begin writing a sequel command so for example if I wanted to create a table here I could create a table we'll just call this test underscore table now I'm not going to go too far into the details here because I'm going to go go into this further in another tutorial but if I just create a very basic table here with one column I can run that query and if i refresh our tables over here then we have a test table with one column called a so in this tutorial we installed a Postgres server we created the database and then we also installed a visual application to where we can visually inspect this database and we've also set it up to where we can now run SQL queries against this database so in the next tutorial we'll start adding tables to our database and we'll go over exactly how to do that so I hope this tutorial was useful for you guys if you have any questions just ask in the comment section below be sure to watch the other videos to get more in depth in the SQL commands and thank you all for watching

Original Description

In this video we will begin learning SQL Basics. To get started writing SQL, we need to first set up a server and a database. The server we will be using for these tutorials is Postgres. We'll walk through how to download, install, and setup PostgreSQL. Then we will create our first database so that we can begin writing SQL code. Let's get started. ✅ Support My Channel Through Patreon: https://www.patreon.com/coreyms ✅ Become a Channel Member: https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join ✅ One-Time Contribution Through PayPal: https://goo.gl/649HFY ✅ Cryptocurrency Donations: Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3 Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33 Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot ✅ Corey's Public Amazon Wishlist http://a.co/inIyro1 ✅ Equipment I Use and Books I Recommend: https://www.amazon.com/shop/coreyschafer ▶️ You Can Find Me On: My Website - http://coreyms.com/ My Second Channel - https://www.youtube.com/c/coreymschafer Facebook - https://www.facebook.com/CoreyMSchafer Twitter - https://twitter.com/CoreyMSchafer Instagram - https://www.instagram.com/coreymschafer/ #SQL #Postgres
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Corey Schafer · Corey Schafer · 52 of 60

1 Web fonts using CSS Font Face
Web fonts using CSS Font Face
Corey Schafer
2 Using Font Awesome in Desktop Applications (OS X)
Using Font Awesome in Desktop Applications (OS X)
Corey Schafer
3 Sublime Text 2: Setup, Package Control, and Settings
Sublime Text 2: Setup, Package Control, and Settings
Corey Schafer
4 ArcGIS API for JavaScript Part 1: Our First Web Map
ArcGIS API for JavaScript Part 1: Our First Web Map
Corey Schafer
5 Mac Tip: Windows' Snapping Feature on Mac with HyperDock
Mac Tip: Windows' Snapping Feature on Mac with HyperDock
Corey Schafer
6 Linux/Mac Terminal Tutorial: Creating Aliases for Commands
Linux/Mac Terminal Tutorial: Creating Aliases for Commands
Corey Schafer
7 ArcGIS API for JavaScript Part 2: Starting Templates
ArcGIS API for JavaScript Part 2: Starting Templates
Corey Schafer
8 Paver Patio Time Lapse
Paver Patio Time Lapse
Corey Schafer
9 Mac Tip: Ways to perform Screen Capturing and Screenshots
Mac Tip: Ways to perform Screen Capturing and Screenshots
Corey Schafer
10 WordPress Plugins: Imsanity
WordPress Plugins: Imsanity
Corey Schafer
11 WordPress Tips: Test your theme with Theme Unit Test and Monster Widget
WordPress Tips: Test your theme with Theme Unit Test and Monster Widget
Corey Schafer
12 Sublime Text 3: Setup, Package Control, and Settings
Sublime Text 3: Setup, Package Control, and Settings
Corey Schafer
13 Understanding Binary, Hexadecimal, Decimal (Base-10), and more
Understanding Binary, Hexadecimal, Decimal (Base-10), and more
Corey Schafer
14 Mac Tip: Adding Folder Stacks to the Dock
Mac Tip: Adding Folder Stacks to the Dock
Corey Schafer
15 CSS Tips and Tricks: Add External URLs to Print Stylesheets
CSS Tips and Tricks: Add External URLs to Print Stylesheets
Corey Schafer
16 JavaScript Arrays: Properties, Methods, and Manipulation (Part 7 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 7 of 7)
Corey Schafer
17 JavaScript Arrays: Properties, Methods, and Manipulation (Part 1 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 1 of 7)
Corey Schafer
18 JavaScript Arrays: Properties, Methods, and Manipulation (Part 5 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 5 of 7)
Corey Schafer
19 JavaScript Arrays: Properties, Methods, and Manipulation (Part 4 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 4 of 7)
Corey Schafer
20 JavaScript Arrays: Properties, Methods, and Manipulation (Part 3 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 3 of 7)
Corey Schafer
21 JavaScript Arrays: Properties, Methods, and Manipulation (Part 2 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 2 of 7)
Corey Schafer
22 JavaScript Arrays: Properties, Methods, and Manipulation (Part 6 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 6 of 7)
Corey Schafer
23 Python Tutorial: if __name__ == '__main__'
Python Tutorial: if __name__ == '__main__'
Corey Schafer
24 Sublime Text Quick Tip: "Go To Definition" Click Shortcut
Sublime Text Quick Tip: "Go To Definition" Click Shortcut
Corey Schafer
25 How to quickly create favicons for the desktop, Apple/Android devices, tablets, and more
How to quickly create favicons for the desktop, Apple/Android devices, tablets, and more
Corey Schafer
26 Easily Resize Multiple Images Using Picasa
Easily Resize Multiple Images Using Picasa
Corey Schafer
27 Easily Resize Multiple Images Using the Mac Terminal
Easily Resize Multiple Images Using the Mac Terminal
Corey Schafer
28 Python Tutorial: virtualenv and why you should use virtual environments
Python Tutorial: virtualenv and why you should use virtual environments
Corey Schafer
29 Python Tutorial: pip - An in-depth look at the package management system
Python Tutorial: pip - An in-depth look at the package management system
Corey Schafer
30 Git Tutorial: Using the Stash Command
Git Tutorial: Using the Stash Command
Corey Schafer
31 How Software Engineers, Developers, and Designers can volunteer their skills
How Software Engineers, Developers, and Designers can volunteer their skills
Corey Schafer
32 Git Tutorial: Diff and Merge Tools
Git Tutorial: Diff and Merge Tools
Corey Schafer
33 Git Tutorial: Change DiffMerge Font-Size on Mac OSX
Git Tutorial: Change DiffMerge Font-Size on Mac OSX
Corey Schafer
34 Sublime Text Quick Tip: Launch Sublime Text from the Terminal
Sublime Text Quick Tip: Launch Sublime Text from the Terminal
Corey Schafer
35 Python Tutorial: str() vs repr()
Python Tutorial: str() vs repr()
Corey Schafer
36 Programming Terms: DRY (Don't Repeat Yourself)
Programming Terms: DRY (Don't Repeat Yourself)
Corey Schafer
37 Programming Terms: String Interpolation
Programming Terms: String Interpolation
Corey Schafer
38 Programming Terms: Idempotence
Programming Terms: Idempotence
Corey Schafer
39 Python Tutorial: Namedtuple - When and why should you use namedtuples?
Python Tutorial: Namedtuple - When and why should you use namedtuples?
Corey Schafer
40 Programming Terms: Mutable vs Immutable
Programming Terms: Mutable vs Immutable
Corey Schafer
41 Python Tutorial: Else Clauses on Loops
Python Tutorial: Else Clauses on Loops
Corey Schafer
42 Overview of Online Learning Resources
Overview of Online Learning Resources
Corey Schafer
43 Mac OS X Terminal Tutorial: Time-Saving Keyboard Shortcuts
Mac OS X Terminal Tutorial: Time-Saving Keyboard Shortcuts
Corey Schafer
44 Git Tutorial for Beginners: Command-Line Fundamentals
Git Tutorial for Beginners: Command-Line Fundamentals
Corey Schafer
45 Quickest and Easiest Way to Run a Local Web-Server
Quickest and Easiest Way to Run a Local Web-Server
Corey Schafer
46 Python Tutorial: Generators - How to use them and the benefits you receive
Python Tutorial: Generators - How to use them and the benefits you receive
Corey Schafer
47 Python Tutorial: Comprehensions - How they work and why you should be using them
Python Tutorial: Comprehensions - How they work and why you should be using them
Corey Schafer
48 Chrome Quick Tip: Quickly Bookmark Open Tabs for Later Viewing
Chrome Quick Tip: Quickly Bookmark Open Tabs for Later Viewing
Corey Schafer
49 Programming Terms: Combinations and Permutations
Programming Terms: Combinations and Permutations
Corey Schafer
50 Git Tutorial: Difference between "add -A", "add -u", "add .", and "add *"
Git Tutorial: Difference between "add -A", "add -u", "add .", and "add *"
Corey Schafer
51 Preparing for a Python Interview: 10 Things You Should Know
Preparing for a Python Interview: 10 Things You Should Know
Corey Schafer
SQL Tutorial for Beginners 1: Installing PostgreSQL and Creating Your First Database
SQL Tutorial for Beginners 1: Installing PostgreSQL and Creating Your First Database
Corey Schafer
53 SQL Tutorial for Beginners 2: Creating Your First Table
SQL Tutorial for Beginners 2: Creating Your First Table
Corey Schafer
54 SQL Tutorial for Beginners 3: INSERT - Adding Records to Your Database
SQL Tutorial for Beginners 3: INSERT - Adding Records to Your Database
Corey Schafer
55 Linux/Mac Terminal Tutorial: Navigating your Filesystem
Linux/Mac Terminal Tutorial: Navigating your Filesystem
Corey Schafer
56 Python: Ex Machina Easter Egg - Hidden Message within the Code
Python: Ex Machina Easter Egg - Hidden Message within the Code
Corey Schafer
57 Mac Tip: New Split Screen Feature in El Capitan
Mac Tip: New Split Screen Feature in El Capitan
Corey Schafer
58 Setting up a Python Development Environment in Eclipse
Setting up a Python Development Environment in Eclipse
Corey Schafer
59 Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits
Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits
Corey Schafer
60 SQL Tutorial for Beginners 4: SELECT - Retrieving Records from Your Database
SQL Tutorial for Beginners 4: SELECT - Retrieving Records from Your Database
Corey Schafer

This tutorial teaches viewers how to set up a PostgreSQL server, create a first database, and install a graphical interface program to manage the database. It covers the basics of SQL commands and prepares viewers for more advanced SQL tutorials.

Key Takeaways
  1. Download and install the Postgres app
  2. Download and install a GUI tool such as PSequel
  3. Start the Postgres server
  4. Create a database using the command line
  5. Connect to the database using the GUI tool
  6. Create a table in the database
💡 Setting up a PostgreSQL server and creating a first database is a crucial step in learning SQL and managing databases.

Related Reads

📰
Exploratory Data Analysis (EDA) — New York city Yellow taxi — Part 1: Data Preparation
Learn to prepare data for exploratory data analysis using the New York City Yellow taxi dataset, a crucial step in understanding and visualizing data insights.
Medium · Data Science
📰
Segmentando Clientes com Análise Fatorial e Clustering
Learn to segment customers using factor analysis and clustering, reducing 14 variables to 4 personas
Medium · Data Science
📰
From Four Platforms to One: How Tongcheng Travel Built a Unified Data Integration Platform with…
Learn how Tongcheng Travel unified four data integration platforms into one using Apache technologies and a batch-stream architecture
Medium · Data Science
📰
Longitudinal Data Infrastructure
Learn how longitudinal data infrastructure can become AI's next foundation for continuity
Medium · AI
Up next
This could be the most perfect data frontend
Matt Williams
Watch →