R SQLite CRUD – Create Read Update Delete

R SQLite CRUD – Create, Insert, Update, Delete – Querying databases using R programming language

R SQLite CRUD – Create, Insert, Update, Delete – Querying databases using R programming language.

get packages

install.packages(“DBI”)
install.packages(“RSQLite”)

create database connection

customerdb = dbConnect(RSQLite::SQLite(), “customerdb.sqlite”)

drop table if exists

dbExecute(customerdb, “DROP table customers”)

create table

dbExecute(customerdb, “CREATE TABLE customers (id INTEGER PRIMARY KEY AUTOINCREMENT, first_name TEXT, last_name TEXT, email TEXT)”)
dbGetQuery(customerdb, “SELECT * FROM customers”)

insert record

dbExecute(customerdb,
“INSERT INTO customers (first_name, last_name, email)
VALUES(‘Ankan’, ‘Basu’, ‘basu.ankan@gmail.com’)” )

update record

dbExecute(customerdb,
“UPDATE customers SET first_name=’UpdatedAnkan’ WHERE id=1” )
dbGetQuery(customerdb, “SELECT * FROM customers”)

delete record

dbExecute(customerdb,
“DELETE from customers WHERE id=1” )
dbGetQuery(customerdb, “SELECT * FROM customers”)

Details of code and presentation file is available on my Github Account @
https://github.com/hydrogeologist/sqlite-R

 1,113 total views,  2 views today

about author

Ankan Basu

ankanbasu@ankanbasu.com

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.