We'll get started with SQL by installing and trying out SQLite.
If you are using the Learn IDE, you don't need to install anything. We've already done this for you :)
If you are on OSX version 10.4 or greater, you probably already have SQLite installed. Find out by opening up the terminal and pasting in:
if you get back
Then you have a working version of sqlite3 already installed on your system. Thanks Apple! Skip ahead to the 'Trying it out' section below!
If not, then there are a couple of ways you can install SQLite.
Via a package manager for your operating system. If you are on Mac, Homebrew is the way to go. You can install it by following the brew installation instructions
After installing Homebrew, install sqlite with:
brew install sqlite Install From Binary
If Homebrew isn't working out for you, you can download one of the pre-compiled binary packages available at the downloads page. Look for your operating system, download and install the appropriate binary.
Okay, let's make sure everything is up and running. In your terminal, type:
This will open a new database file called test_sqlite.db and open it in the sqlite prompt. You should see something like:
SQLite version 3.7.12 2013-03-19 12:42:02 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite>
You are now looking at the sqlite prompt.
Let's create a database table called "Test Table":
sqlite> create table test_table(id); sqlite> .quit
You should have created a test_sqlite.db file. Either open up the directory you are working from in finder or type
open . into your terminal. You should see that, inside whatever directory you've been working in, you have your
Top-Tip: All SQL statements that you write in your terminal, inside the sqlite prompt,
sqlite3>, must be terminated with a semi-colon
;. If you hit
enter without adding a semi-colon to the end of your line, you will be trapped! Don't worry though, just add that
; on the new line and hit
enter again. The only command that doesn't require, and in fact doesn't even work with, a
; is the
View SQL Intro and Installation on Learn.co and start learning to code for free.