SELECT * FROM celebs;
Query Results
id name age
1 Justin Bieber 22
2 Beyonce Knowles 33
3 Jeremy Lin 26
4 Taylor Swift 26
Database Schema
celebs
name type
id INTEGER
name TEXT
age INTEGER
Rows: 4
Relational Databases
Nice work! In one line of code, you returned information from a relational database.
SELECT * FROM celebs;
We’ll take a look at what this code means soon, for now, let’s focus on what
relational databases are and how they are organized.
A relational database is a database that organizes information into one or more
tables. Here, the relational database contains one table.
A table is a collection of data organized into rows and columns. Tables are
sometimes referred to as relations. Here the table is celebs.
A column is a set of data values of a particular type. Here, id, name, and age are the
columns.
A row is a single record in a table. The first row in the celebs table has:
An id of 1
A name of Justin Bieber
An age of 22
All data stored in a relational database is of a certain data type. Some of the most
common data types are:
Statements
The code below is a SQL statement. A statement is text that the database recognizes
Statements always end in a
as a valid command.
semicolon ;.
CREATE TABLE table_name (
column_1 data_type,
column_2 data_type,
column_3 data_type
);
Let’s break down the components of a statement:
1. CREATE TABLE is a clause. Clauses perform specific tasks in SQL. By convention,
clauses are written in capital letters. Clauses can also be referred to as
commands.
2. table_name refers to the name of the table that the command is applied to.
3. (column_1 data_type, column_2 data_type, column_3 data_type) is a parameter.
A parameter is a list of columns, data types, or values that are passed to a
clause as an argument. Here, the parameter is a list of column names and the
associated data type.
The structure of SQL statements vary. The number of lines used does not matter. A
statement can be written all on one line, or split up across multiple lines if it makes it
easier to read. In this course, you will become familiar with the structure of common
statements.
INTEGER, a positive or negative whole number
TEXT, a text string
DATE, the date formatted as YYYY-MM-DD
REAL, a decimal value
Create
CREATE statements allow us to create a new table in the database. You can use
the CREATE statement anytime you want to create a new table from scratch. The
statement below creates a new table named celebs.
CREATE TABLE celebs (
id INTEGER,
name TEXT,
age INTEGER
);
1. CREATE TABLE is a clause that tells SQL you want to create a new table.
2. celebs is the name of the table.
3. (id INTEGER, name TEXT, age INTEGER) is a list of parameters defining each column,
or attribute in the table and its data type:
id is the first column in the table. It stores values of data type INTEGER
name is the second column in the table. It stores values of data type TEXT
age is the third column in the table. It stores values of data type INTEGER