SQL Intro and Installation
Overview
We'll get started with SQL by installing and trying out SQLite.
Objectives
Check to see if SQLite is installed on your computer via a terminal command
Install SQLite on your computer
Create and open a database file and table
End all SQL commands using proper semicolon notation
Exit out of SQLite using the .quit command
Installing SQL
If you are using the Learn IDE, you don't need to install anything. We've already done this for you :)
Macs Make It Easy
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
/usr/bin/sqlite3
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.
Manual Installation Options
Install With Homebrew:
After installing Homebrew, install sqlite with:
Trying it out
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:
You are now looking at the sqlite prompt.
Let's create a database table called "Test Table":
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 test_sqlite.db
file.
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 .quit
command.
Resources
Last updated