Skip to content

Instantly share code, notes, and snippets.

@spenserhuang
Last active August 29, 2015 14:20
Show Gist options
  • Save spenserhuang/e4b8dc0f5fb92b6942a3 to your computer and use it in GitHub Desktop.
Save spenserhuang/e4b8dc0f5fb92b6942a3 to your computer and use it in GitHub Desktop.
Solution for Database Drill: Intro to SQLite
# Solution for Challenge: Database Drill: Intro to SQLite. Started 2015-05-09T04:09:18+00:00
sqlite>
sqlite> .schema
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name VARCHAR(64) NOT NULL,
last_name VARCHAR(64) NOT NULL,
email VARCHAR(128) UNIQUE NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL
, nicknames VARCHAR(64) NOT NULL DEFAULT(1));
sqlite> SELECT * FROM users;
sqlite> INSERT INTO users
...> (first_name, last_name, email, created_at, updated_at)
...> VALUES
...> ('Jessie', 'Farmers', '[email protected]', DATETIME('now'), DATETIME('now'));
sqlite> .schema
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name VARCHAR(64) NOT NULL,
last_name VARCHAR(64) NOT NULL,
email VARCHAR(128) UNIQUE NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL
, nicknames VARCHAR(64) NOT NULL DEFAULT(1));
sqlite> SELECT * FROM users
...> ;
id first_name last_name email created_at updated_at nicknames
---------- ---------- ---------- --------------------- ------------------- ------------------- ----------
1 Jessie Farmers [email protected] 2015-05-09 21:15:52 2015-05-09 21:15:52 1
sqlite> UPDATE users
...> SET nicknames = 'Ninja Coder', updated_at = DATETIME('now')
...> WHERE id = 1;
sqlite> SELECT * FROM users
...> ;
id first_name last_name email created_at updated_at nicknames
---------- ---------- ---------- --------------------- ------------------- ------------------- -----------
1 Jessie Farmers [email protected] 2015-05-09 21:15:52 2015-05-09 21:18:42 Ninja Coder
sqlite>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment