2020-01-24 14:58
Page 1

Databases (TDA357, DIT621)

Lecture 2: SQL 1

Page 2


Basic SQL

Page 3

Next time

More SQL

Page 4

Relational Databases

The relational data model

Page 5


A database with information about countries

Page 6

Database schema

Page 7

SQL = Structured Query Language

Page 8

PostgreSQL practical things

Commands to run in a terminal window

Page 9

PostgreSQL Live demo


Page 10

SQL: Creating tables

Page 11

Inserting new rows in a table

Page 12

Inserting data from a file into a table


Page 13


Page 14

The result of a query is another table, containing

Page 15

Some general observations about SQL

Page 16

Modifying data in tables

Example: a baby has been born in Finland

Page 17

Deleting data from tables

Page 18

More precise types

Page 19

Are missing values allowed?

Page 20

Duplicated values

Page 21

Primary Key

Page 22


Table schema with primary key

Page 23

Order By

Page 24

Queries with computations

Example: population density

Page 25

Aggregation (Group By)

Page 26

SQL Summary

DB Management 1: creating and deleting tables

Page 27
SQL Summary

DB Management 2: modifying the contents of tables

Page 28
SQL Summary

DB Queries

Page 29
SQL Summary

Values and conditions

Page 30


All the parts of the SELECT statements are optional.

Page 31

Local definitions in queries

Page 32

For reference

Page 33

Next time

More SQL

Page 34

The end for today