No feedback found for this session
| Booking link | Date |
|---|---|
| Getting data into SQL | 10:00-11:30 Tue 27th January 2026 |
KIND learning network training materials by KIND learning network is licensed under CC BY-SA 4.0
November 27, 2025
No feedback found for this session
| Booking link | Date |
|---|---|
| Getting data into SQL | 10:00-11:30 Tue 27th January 2026 |
This session is all about getting data into, and out of SQL. We’ll look at:
You will need a free posit.cloud account. Please set this up and check that you have access before the session begins
Once you’ve logged-in to posit.cloud, please create a new Rstudio project 
In that project, create a new R script: 
Copy and paste the following R code into that script:
## install and attach R packages
pkg <- c("dbplyr", "RSQLite", "palmerpenguins")
install.packages(setdiff(pkg, rownames(installed.packages())))
library(dbplyr)
library(dplyr)
library(palmerpenguins)
conn <- src_memdb() # create an sqlite db in memorySource button
File menu)
CREATE TABLE clients (chi varchar(10) NOT NULL,
name varchar(255),
birthdate date,
PRIMARY KEY (chi));what’s a table? the container for some data
need to set data types - SQL is typed
| type | what |
|---|---|
| CHAR | fixed length char |
| VARCHAR | variable length char |
| INT | whole number |
| DOUBLE | decimal number |
| DATE | date |
| DATETIME | date-time |
then test:
| chi | name | birthdate |
|---|
should be empty, that’s just fine for now. Let’s add some data to that table to make it more useful:
insert data into your table using the INSERT INTO keyword:
and then check:
| chi | name | birthdate |
|---|---|---|
| 1204851425 | Mr Odds | 1985-04-12 |
It’s good practice to specify the columns by name, especially if you need to include partial data:
| chi | name | birthdate |
|---|---|---|
| 1204851425 | Mr Odds | 1985-04-12 |
| 0701720842 | NA | 1972-01-07 |
PRIMARY KEY (chi) while creating our table, we made the chi column special: this is the primary key of the table livesINSERT INTO clients VALUES
("0411016548", "The Moog", "2001-11-04"),
("3003627534", "One McIrey", "1962-03-30"),
("2407864568", "Dr Stamps", "1986-07-24");| chi | name | birthdate |
|---|---|---|
| 1204851425 | Mr Odds | 1985-04-12 |
| 0701720842 | NA | 1972-01-07 |
| 0411016548 | The Moog | 2001-11-04 |
| 3003627534 | One McIrey | 1962-03-30 |
| 2407864568 | Dr Stamps | 1986-07-24 |
| chi | name | birthdate |
|---|---|---|
| 1204851425 | Mr Odds | 1985-04-12 |
| 0701720842 | David Lemon | 1972-01-07 |
| 0411016548 | The Moog | 2001-11-04 |
| 3003627534 | One McIrey | 1962-03-30 |
| 2407864568 | Dr Stamps | 1986-07-24 |
| chi | name | birthdate | length |
|---|---|---|---|
| 1204851425 | Mr Odds | 1985-04-12 | 10 |
| 0701720842 | David Lemon | 1972-01-07 | 10 |
| 0411016548 | The Moog | 2001-11-04 | 10 |
| 3003627534 | One McIrey | 1962-03-30 | 10 |
| 2407864568 | Dr Stamps | 1986-07-24 | 10 |
| chi | name | birthdate | length |
|---|---|---|---|
| 1204851425 | Mr Odds | 1985-04-12 | 12 |
| 0701720842 | David Lemon | 1972-01-07 | 10 |
| 0411016548 | The Moog | 2001-11-04 | 10 |
| 3003627534 | One McIrey | 1962-03-30 | 10 |
| 2407864568 | Dr Stamps | 1986-07-24 | 12 |
| chi | name | birthdate |
|---|---|---|
| 1204851425 | Mr Odds | 1985-04-12 |
| 0701720842 | David Lemon | 1972-01-07 |
| 0411016548 | The Moog | 2001-11-04 |
| 3003627534 | One McIrey | 1962-03-30 |
| 2407864568 | Dr Stamps | 1986-07-24 |
Like all our courses and sessions, this is a team effort, and I thank the network as a whole for their encouragements and contributions. Specific thanks in this case go to Amanda King (NHS GGC), Steven Knapman (NHS Fife), and James McMahon (Public Health Scotland), and to the members of the pilot cohort for this session.