SlideShare a Scribd company logo
1 of 28
DataCamp Introduction to Relational Databases in SQL
Your first database
INTRODUCTION TO RELATIONAL DATABASES IN SQL
Timo Grossenbacher
Data Journalist
DataCamp Introduction to Relational Databases in SQL
Investigating universities in Switzerland
DataCamp Introduction to Relational Databases in SQL
A relational database:
real-life entities become tables
reduced redundancy
data integrity by relationships
e.g. professors, universities,
companies
e.g. only one entry in companies for
the bank "Credit Suisse"
e.g. a professor can work at multiple
universities and companies, a
company can employ multiple
professors
DataCamp Introduction to Relational Databases in SQL
Throughout this course you will:
work with the data I used for my investigation
create a relational database from scratch
learn three concepts:
constraints
keys
referential integrity
You'll need: Basic understanding of SQL, as taught in .Intro to SQL for Data Science
DataCamp Introduction to Relational Databases in SQL
Your first duty: Have a look at the PostgreSQL database
SELECT table_schema, table_name
FROM information_schema.tables;
table_schema | table_name
--------------------+---------------------------------------
pg_catalog | pg_statistic
pg_catalog | pg_type
pg_catalog | pg_policy
pg_catalog | pg_authid
pg_catalog | pg_shadow
public | university_professors
pg_catalog | pg_settings
pg_catalog | pg_hba_file_rules
pg_catalog | pg_file_settings
pg_catalog | pg_config
...
DataCamp Introduction to Relational Databases in SQL
Have a look at the columns of a certain table
SELECT table_name, column_name, data_type
FROM information_schema.columns
WHERE table_name = 'pg_config';
table_name | column_name | data_type
------------+-------------+-----------
pg_config | name | text
pg_config | setting | text
DataCamp Introduction to Relational Databases in SQL
Let's do this.
INTRODUCTION TO RELATIONAL DATABASES IN SQL
DataCamp Introduction to Relational Databases in SQL
Tables: At the core of every
database
INTRODUCTION TO RELATIONAL DATABASES IN SQL
Timo Grossenbacher
Data Journalist
DataCamp Introduction to Relational Databases in SQL
Redundancy in the university_professors table
SELECT * FROM
FROM university_professors
LIMIT 3;
DataCamp Introduction to Relational Databases in SQL
Redundancy in the university_professors table
-[ RECORD 1 ]--------+-------------------------------------------------
firstname | Karl
lastname | Aberer
university | ETH Lausanne
university_shortname | EPF
university_city | Lausanne
function | Chairman of L3S Advisory Board
organization | L3S Advisory Board
organization_sector | Education & research
-[ RECORD 2 ]--------+-------------------------------------------------
firstname | Karl
lastname | Aberer
university | ETH Lausanne
university_shortname | EPF
university_city | Lausanne
function | Member Conseil of Zeno-Karl Schindler Foundation
organization | Zeno-Karl Schindler Foundation
organization_sector | Education & research
-[ RECORD 3 ]--------+-------------------------------------------------
firstname | Karl
lastname | Aberer
(truncated)
function | Member of Conseil Fondation IDIAP
organization | Fondation IDIAP
(truncated)
DataCamp Introduction to Relational Databases in SQL
DataCamp Introduction to Relational Databases in SQL
Currently: One "entity type" in the database
DataCamp Introduction to Relational Databases in SQL
A better database model with three entity types
Old: New:
DataCamp Introduction to Relational Databases in SQL
A better database model with four entity types
DataCamp Introduction to Relational Databases in SQL
Create new tables with CREATE TABLE
CREATE TABLE table_name (
column_a data_type,
column_b data_type,
column_c data_type
);
DataCamp Introduction to Relational Databases in SQL
Create new tables with CREATE TABLE
CREATE TABLE weather (
clouds text,
temperature numeric,
weather_station char(5)
);
DataCamp Introduction to Relational Databases in SQL
Let's practice!
INTRODUCTION TO RELATIONAL DATABASES IN SQL
DataCamp Introduction to Relational Databases in SQL
Update your database as
the structure changes
INTRODUCTION TO RELATIONAL DATABASES IN SQL
Timo Grossenbacher
Data Journalist
DataCamp Introduction to Relational Databases in SQL
The current database model
DataCamp Introduction to Relational Databases in SQL
The current database model
DataCamp Introduction to Relational Databases in SQL
Only store DISTINCT data in the new tables
SELECT COUNT(*)
FROM university_professors;
count
-------
1377
SELECT COUNT(DISTINCT organization)
FROM university_professors;
count
-------
1287
DataCamp Introduction to Relational Databases in SQL
INSERT DISTINCT records INTO the new tables
INSERT INTO organizations
SELECT DISTINCT organization,
organization_sector
FROM university_professors;
Output: INSERT 0 1287
INSERT INTO organizations
SELECT organization,
organization_sector
FROM university_professors;
Output: INSERT 0 1377
DataCamp Introduction to Relational Databases in SQL
The INSERT INTO statement
INSERT INTO table_name (column_a, column_b)
VALUES ("value_a", "value_b");
DataCamp Introduction to Relational Databases in SQL
RENAME a COLUMN in affiliations
CREATE TABLE affiliations (
firstname text,
lastname text,
university_shortname text,
function text,
organisation text
);
ALTER TABLE table_name
RENAME COLUMN old_name TO new_name;
DataCamp Introduction to Relational Databases in SQL
DROP a COLUMN in affiliations
CREATE TABLE affiliations (
firstname text,
lastname text,
university_shortname text,
function text,
organization text
);
ALTER TABLE table_name
DROP COLUMN column_name;
DataCamp Introduction to Relational Databases in SQL
A professor is uniquely identified by firstname, lastname only
SELECT DISTINCT firstname, lastname,
university_shortname
FROM university_professors
ORDER BY lastname;
-[ RECORD 1 ]--------+-------------
firstname | Karl
lastname | Aberer
university_shortname | EPF
-[ RECORD 2 ]--------+-------------
firstname | Reza Shokrollah
lastname | Abhari
university_shortname | ETH
-[ RECORD 3 ]--------+-------------
firstname | Georges
lastname | Abou Jaoudé
university_shortname | EPF
(truncated)
(551 records)
SELECT DISTINCT firstname, lastname
FROM university_professors
ORDER BY lastname;
-[ RECORD 1 ]----------------------
firstname | Karl
lastname | Aberer
-[ RECORD 2 ]----------------------
firstname | Reza Shokrollah
lastname | Abhari
-[ RECORD 3 ]----------------------
firstname | Georges
lastname | Abou Jaoudé
(truncated)
(551 records)
DataCamp Introduction to Relational Databases in SQL
A professor is uniquely identified by firstname, lastname only
DataCamp Introduction to Relational Databases in SQL
Let's get to work!
INTRODUCTION TO RELATIONAL DATABASES IN SQL

More Related Content

What's hot

BAS 150 Lesson 4 Lecture
BAS 150 Lesson 4 LectureBAS 150 Lesson 4 Lecture
BAS 150 Lesson 4 LectureWake Tech BAS
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL ISankhya_Analytics
 
BAS 150 Lesson 6 Lecture
BAS 150 Lesson 6 LectureBAS 150 Lesson 6 Lecture
BAS 150 Lesson 6 LectureWake Tech BAS
 
Base SAS Statistics Procedures
Base SAS Statistics ProceduresBase SAS Statistics Procedures
Base SAS Statistics Proceduresguest2160992
 
Sas Macro Examples
Sas Macro ExamplesSas Macro Examples
Sas Macro ExamplesSASTechies
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETEAbrar ali
 
SAS cheat sheet
SAS cheat sheetSAS cheat sheet
SAS cheat sheetAli Ajouz
 
LaTeX Part 1
LaTeX Part 1LaTeX Part 1
LaTeX Part 1awv7t
 
Relational database- Fundamentals
Relational database- FundamentalsRelational database- Fundamentals
Relational database- FundamentalsMohammed El Hedhly
 
When & Why\'s of Denormalization
When & Why\'s of DenormalizationWhen & Why\'s of Denormalization
When & Why\'s of DenormalizationAliya Saldanha
 
Introduction to sas
Introduction to sasIntroduction to sas
Introduction to sasAjay Ohri
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management Systemsweetysweety8
 
Sql interview questions and answers
Sql interview questions and  answersSql interview questions and  answers
Sql interview questions and answerssheibansari
 

What's hot (20)

[PHPUGPH] PHP Roadshow - MySQL
[PHPUGPH] PHP Roadshow - MySQL[PHPUGPH] PHP Roadshow - MySQL
[PHPUGPH] PHP Roadshow - MySQL
 
BAS 150 Lesson 4 Lecture
BAS 150 Lesson 4 LectureBAS 150 Lesson 4 Lecture
BAS 150 Lesson 4 Lecture
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
 
Denormalization
DenormalizationDenormalization
Denormalization
 
BAS 150 Lesson 6 Lecture
BAS 150 Lesson 6 LectureBAS 150 Lesson 6 Lecture
BAS 150 Lesson 6 Lecture
 
Base SAS Statistics Procedures
Base SAS Statistics ProceduresBase SAS Statistics Procedures
Base SAS Statistics Procedures
 
Sas Macro Examples
Sas Macro ExamplesSas Macro Examples
Sas Macro Examples
 
T-SQL Overview
T-SQL OverviewT-SQL Overview
T-SQL Overview
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
SAS cheat sheet
SAS cheat sheetSAS cheat sheet
SAS cheat sheet
 
Lecture 2b lists
Lecture 2b listsLecture 2b lists
Lecture 2b lists
 
LaTeX Part 1
LaTeX Part 1LaTeX Part 1
LaTeX Part 1
 
Relational database- Fundamentals
Relational database- FundamentalsRelational database- Fundamentals
Relational database- Fundamentals
 
Sql basics
Sql basicsSql basics
Sql basics
 
SAS BASICS
SAS BASICSSAS BASICS
SAS BASICS
 
When & Why\'s of Denormalization
When & Why\'s of DenormalizationWhen & Why\'s of Denormalization
When & Why\'s of Denormalization
 
Introduction to sas
Introduction to sasIntroduction to sas
Introduction to sas
 
Adbms
AdbmsAdbms
Adbms
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management System
 
Sql interview questions and answers
Sql interview questions and  answersSql interview questions and  answers
Sql interview questions and answers
 

Similar to relational database

Intro to SQL for Beginners
Intro to SQL for BeginnersIntro to SQL for Beginners
Intro to SQL for BeginnersProduct School
 
MIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresMIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresSteven Johnson
 
Data_base.pptx
Data_base.pptxData_base.pptx
Data_base.pptxMohit89650
 
Database queries
Database queriesDatabase queries
Database queriesIIUM
 
Advanced Database Systems - Presentation 1 with quiz.pptx
Advanced Database Systems - Presentation 1 with quiz.pptxAdvanced Database Systems - Presentation 1 with quiz.pptx
Advanced Database Systems - Presentation 1 with quiz.pptxEllenGracePorras
 
DBMS_INTRODUCTION OF SQL
DBMS_INTRODUCTION OF SQLDBMS_INTRODUCTION OF SQL
DBMS_INTRODUCTION OF SQLAzizul Mamun
 
Relational data model
Relational data modelRelational data model
Relational data modelSURBHI SAROHA
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredDanish Mehraj
 
Azure Data Fundamentals DP 900 Full Course
Azure Data Fundamentals DP 900 Full CourseAzure Data Fundamentals DP 900 Full Course
Azure Data Fundamentals DP 900 Full CoursePiyush sachdeva
 
Adbms 21 sql 99 schema definition constraints and queries
Adbms 21 sql 99 schema definition constraints and queriesAdbms 21 sql 99 schema definition constraints and queries
Adbms 21 sql 99 schema definition constraints and queriesVaibhav Khanna
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfTamiratDejene1
 

Similar to relational database (20)

Chapter2
Chapter2Chapter2
Chapter2
 
Intro to SQL for Beginners
Intro to SQL for BeginnersIntro to SQL for Beginners
Intro to SQL for Beginners
 
MIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresMIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome Measures
 
Data_base.pptx
Data_base.pptxData_base.pptx
Data_base.pptx
 
Database queries
Database queriesDatabase queries
Database queries
 
Advanced Database Systems - Presentation 1 with quiz.pptx
Advanced Database Systems - Presentation 1 with quiz.pptxAdvanced Database Systems - Presentation 1 with quiz.pptx
Advanced Database Systems - Presentation 1 with quiz.pptx
 
DBMS LAB M.docx
DBMS LAB M.docxDBMS LAB M.docx
DBMS LAB M.docx
 
Sql project ..
Sql project ..Sql project ..
Sql project ..
 
Ch3
Ch3Ch3
Ch3
 
DBMS_INTRODUCTION OF SQL
DBMS_INTRODUCTION OF SQLDBMS_INTRODUCTION OF SQL
DBMS_INTRODUCTION OF SQL
 
Relational data model
Relational data modelRelational data model
Relational data model
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics Covered
 
My sql1
My sql1My sql1
My sql1
 
Azure Data Fundamentals DP 900 Full Course
Azure Data Fundamentals DP 900 Full CourseAzure Data Fundamentals DP 900 Full Course
Azure Data Fundamentals DP 900 Full Course
 
Sql
SqlSql
Sql
 
Adbms 21 sql 99 schema definition constraints and queries
Adbms 21 sql 99 schema definition constraints and queriesAdbms 21 sql 99 schema definition constraints and queries
Adbms 21 sql 99 schema definition constraints and queries
 
Data base.ppt
Data base.pptData base.ppt
Data base.ppt
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
 
Sql.pptx
Sql.pptxSql.pptx
Sql.pptx
 
LECTURE NOTES.pdf
LECTURE NOTES.pdfLECTURE NOTES.pdf
LECTURE NOTES.pdf
 

Recently uploaded

社内勉強会資料_Object Recognition as Next Token Prediction
社内勉強会資料_Object Recognition as Next Token Prediction社内勉強会資料_Object Recognition as Next Token Prediction
社内勉強会資料_Object Recognition as Next Token PredictionNABLAS株式会社
 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...kumargunjan9515
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...gajnagarg
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Klinik kandungan
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxronsairoathenadugay
 
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...nirzagarg
 
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...HyderabadDolls
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...gajnagarg
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNKTimothy Spann
 
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...kumargunjan9515
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...nirzagarg
 
Statistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbersStatistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numberssuginr1
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubaikojalkojal131
 
Call Girls In GOA North Goa +91-8588052666 Direct Cash Escorts Service
Call Girls In GOA North Goa +91-8588052666 Direct Cash Escorts ServiceCall Girls In GOA North Goa +91-8588052666 Direct Cash Escorts Service
Call Girls In GOA North Goa +91-8588052666 Direct Cash Escorts Servicenishakur201
 
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...kumargunjan9515
 
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...HyderabadDolls
 
Vastral Call Girls Book Now 7737669865 Top Class Escort Service Available
Vastral Call Girls Book Now 7737669865 Top Class Escort Service AvailableVastral Call Girls Book Now 7737669865 Top Class Escort Service Available
Vastral Call Girls Book Now 7737669865 Top Class Escort Service Availablegargpaaro
 
Oral Sex Call Girls Kashmiri Gate Delhi Just Call 👉👉 📞 8448380779 Top Class C...
Oral Sex Call Girls Kashmiri Gate Delhi Just Call 👉👉 📞 8448380779 Top Class C...Oral Sex Call Girls Kashmiri Gate Delhi Just Call 👉👉 📞 8448380779 Top Class C...
Oral Sex Call Girls Kashmiri Gate Delhi Just Call 👉👉 📞 8448380779 Top Class C...Delhi Call girls
 

Recently uploaded (20)

社内勉強会資料_Object Recognition as Next Token Prediction
社内勉強会資料_Object Recognition as Next Token Prediction社内勉強会資料_Object Recognition as Next Token Prediction
社内勉強会資料_Object Recognition as Next Token Prediction
 
Call Girls in G.T.B. Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in G.T.B. Nagar  (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in G.T.B. Nagar  (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in G.T.B. Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
 
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
 
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
 
Abortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
Abortion pills in Doha {{ QATAR }} +966572737505) Get CytotecAbortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
Abortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
 
Statistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbersStatistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbers
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubai
 
Call Girls In GOA North Goa +91-8588052666 Direct Cash Escorts Service
Call Girls In GOA North Goa +91-8588052666 Direct Cash Escorts ServiceCall Girls In GOA North Goa +91-8588052666 Direct Cash Escorts Service
Call Girls In GOA North Goa +91-8588052666 Direct Cash Escorts Service
 
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
 
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
 
Vastral Call Girls Book Now 7737669865 Top Class Escort Service Available
Vastral Call Girls Book Now 7737669865 Top Class Escort Service AvailableVastral Call Girls Book Now 7737669865 Top Class Escort Service Available
Vastral Call Girls Book Now 7737669865 Top Class Escort Service Available
 
Oral Sex Call Girls Kashmiri Gate Delhi Just Call 👉👉 📞 8448380779 Top Class C...
Oral Sex Call Girls Kashmiri Gate Delhi Just Call 👉👉 📞 8448380779 Top Class C...Oral Sex Call Girls Kashmiri Gate Delhi Just Call 👉👉 📞 8448380779 Top Class C...
Oral Sex Call Girls Kashmiri Gate Delhi Just Call 👉👉 📞 8448380779 Top Class C...
 

relational database

  • 1. DataCamp Introduction to Relational Databases in SQL Your first database INTRODUCTION TO RELATIONAL DATABASES IN SQL Timo Grossenbacher Data Journalist
  • 2. DataCamp Introduction to Relational Databases in SQL Investigating universities in Switzerland
  • 3. DataCamp Introduction to Relational Databases in SQL A relational database: real-life entities become tables reduced redundancy data integrity by relationships e.g. professors, universities, companies e.g. only one entry in companies for the bank "Credit Suisse" e.g. a professor can work at multiple universities and companies, a company can employ multiple professors
  • 4. DataCamp Introduction to Relational Databases in SQL Throughout this course you will: work with the data I used for my investigation create a relational database from scratch learn three concepts: constraints keys referential integrity You'll need: Basic understanding of SQL, as taught in .Intro to SQL for Data Science
  • 5. DataCamp Introduction to Relational Databases in SQL Your first duty: Have a look at the PostgreSQL database SELECT table_schema, table_name FROM information_schema.tables; table_schema | table_name --------------------+--------------------------------------- pg_catalog | pg_statistic pg_catalog | pg_type pg_catalog | pg_policy pg_catalog | pg_authid pg_catalog | pg_shadow public | university_professors pg_catalog | pg_settings pg_catalog | pg_hba_file_rules pg_catalog | pg_file_settings pg_catalog | pg_config ...
  • 6. DataCamp Introduction to Relational Databases in SQL Have a look at the columns of a certain table SELECT table_name, column_name, data_type FROM information_schema.columns WHERE table_name = 'pg_config'; table_name | column_name | data_type ------------+-------------+----------- pg_config | name | text pg_config | setting | text
  • 7. DataCamp Introduction to Relational Databases in SQL Let's do this. INTRODUCTION TO RELATIONAL DATABASES IN SQL
  • 8. DataCamp Introduction to Relational Databases in SQL Tables: At the core of every database INTRODUCTION TO RELATIONAL DATABASES IN SQL Timo Grossenbacher Data Journalist
  • 9. DataCamp Introduction to Relational Databases in SQL Redundancy in the university_professors table SELECT * FROM FROM university_professors LIMIT 3;
  • 10. DataCamp Introduction to Relational Databases in SQL Redundancy in the university_professors table -[ RECORD 1 ]--------+------------------------------------------------- firstname | Karl lastname | Aberer university | ETH Lausanne university_shortname | EPF university_city | Lausanne function | Chairman of L3S Advisory Board organization | L3S Advisory Board organization_sector | Education & research -[ RECORD 2 ]--------+------------------------------------------------- firstname | Karl lastname | Aberer university | ETH Lausanne university_shortname | EPF university_city | Lausanne function | Member Conseil of Zeno-Karl Schindler Foundation organization | Zeno-Karl Schindler Foundation organization_sector | Education & research -[ RECORD 3 ]--------+------------------------------------------------- firstname | Karl lastname | Aberer (truncated) function | Member of Conseil Fondation IDIAP organization | Fondation IDIAP (truncated)
  • 11. DataCamp Introduction to Relational Databases in SQL
  • 12. DataCamp Introduction to Relational Databases in SQL Currently: One "entity type" in the database
  • 13. DataCamp Introduction to Relational Databases in SQL A better database model with three entity types Old: New:
  • 14. DataCamp Introduction to Relational Databases in SQL A better database model with four entity types
  • 15. DataCamp Introduction to Relational Databases in SQL Create new tables with CREATE TABLE CREATE TABLE table_name ( column_a data_type, column_b data_type, column_c data_type );
  • 16. DataCamp Introduction to Relational Databases in SQL Create new tables with CREATE TABLE CREATE TABLE weather ( clouds text, temperature numeric, weather_station char(5) );
  • 17. DataCamp Introduction to Relational Databases in SQL Let's practice! INTRODUCTION TO RELATIONAL DATABASES IN SQL
  • 18. DataCamp Introduction to Relational Databases in SQL Update your database as the structure changes INTRODUCTION TO RELATIONAL DATABASES IN SQL Timo Grossenbacher Data Journalist
  • 19. DataCamp Introduction to Relational Databases in SQL The current database model
  • 20. DataCamp Introduction to Relational Databases in SQL The current database model
  • 21. DataCamp Introduction to Relational Databases in SQL Only store DISTINCT data in the new tables SELECT COUNT(*) FROM university_professors; count ------- 1377 SELECT COUNT(DISTINCT organization) FROM university_professors; count ------- 1287
  • 22. DataCamp Introduction to Relational Databases in SQL INSERT DISTINCT records INTO the new tables INSERT INTO organizations SELECT DISTINCT organization, organization_sector FROM university_professors; Output: INSERT 0 1287 INSERT INTO organizations SELECT organization, organization_sector FROM university_professors; Output: INSERT 0 1377
  • 23. DataCamp Introduction to Relational Databases in SQL The INSERT INTO statement INSERT INTO table_name (column_a, column_b) VALUES ("value_a", "value_b");
  • 24. DataCamp Introduction to Relational Databases in SQL RENAME a COLUMN in affiliations CREATE TABLE affiliations ( firstname text, lastname text, university_shortname text, function text, organisation text ); ALTER TABLE table_name RENAME COLUMN old_name TO new_name;
  • 25. DataCamp Introduction to Relational Databases in SQL DROP a COLUMN in affiliations CREATE TABLE affiliations ( firstname text, lastname text, university_shortname text, function text, organization text ); ALTER TABLE table_name DROP COLUMN column_name;
  • 26. DataCamp Introduction to Relational Databases in SQL A professor is uniquely identified by firstname, lastname only SELECT DISTINCT firstname, lastname, university_shortname FROM university_professors ORDER BY lastname; -[ RECORD 1 ]--------+------------- firstname | Karl lastname | Aberer university_shortname | EPF -[ RECORD 2 ]--------+------------- firstname | Reza Shokrollah lastname | Abhari university_shortname | ETH -[ RECORD 3 ]--------+------------- firstname | Georges lastname | Abou Jaoudé university_shortname | EPF (truncated) (551 records) SELECT DISTINCT firstname, lastname FROM university_professors ORDER BY lastname; -[ RECORD 1 ]---------------------- firstname | Karl lastname | Aberer -[ RECORD 2 ]---------------------- firstname | Reza Shokrollah lastname | Abhari -[ RECORD 3 ]---------------------- firstname | Georges lastname | Abou Jaoudé (truncated) (551 records)
  • 27. DataCamp Introduction to Relational Databases in SQL A professor is uniquely identified by firstname, lastname only
  • 28. DataCamp Introduction to Relational Databases in SQL Let's get to work! INTRODUCTION TO RELATIONAL DATABASES IN SQL