Code Monkey home page Code Monkey logo

practice-for-week-10-sql-practice-sqlite3-cli's Introduction

Exercise: SQLite3 CLI

Now, you will practice using the Command Line Interface (CLI) in SQLite3.

Getting Started

Download starter. cd into the sql-practice folder.

As you work, write down any questions you have for the upcoming discussion session.

Step 1: Use built-in documentation

Run sqlite3. You can begin with no database.

Tip: Notice the prompt changes to "sqlite>". That's how you know you will be able to run SQL statements and SQLite3 commands.

You can view the available commands for SQLite using .help. Run this now and look for the commands to

  • View the list of tables
  • View the table schema

Write down what you found. You'll need to use them in the next section.

Exit the CLI.

Tip: If you can't remember the keyboard shortcut you can look again at the built-in documentation to see if there is a command for exiting the CLI.

Hint https://sqlite.org/cli.html

Step 2: Run sqlite3 to explore a database

Start SQLite on a new database named example.db.

View the tables in the database by entering the command you found in Step 1..tables
View the schema of the database by entering the command you found in Step 1..schema
Think about it: Do you know why you don't find any tables or schema?Because the database is new and no tables have been created inside of the new database.

Run the command .read example.sql. This will execute the SQL in the example.sql file.

Repeat the command for viewing the tables in the database. You should see

samples

Repeat the command for viewing the schema of the database. You should see

CREATE TABLE samples (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);
CREATE TABLE sqlite_sequence(name,seq);

Finally, run a simple query to see the data in the samples table by entering

SELECT * FROM samples;

This should show you

1|You found me!
2|Yippee!!
3|Yay!!!

Step 3: Show the column names in the results

The SQLite3 CLI has configuration options that you can set, one of which is to show the names of each of the columns in the rows of the query result.

Look for a command in the list of SQLite3 commands (.help) to turn on headers and execute it..headers on

Now, you should be able to see the names of the columns for any query result returned in the SQLite3 CLI.

Run the same query in the previous step

SELECT * FROM samples;

This should show you the results with the names of the columns as the first row

id|name
1|You found me!
2|Yippee!!
3|Yay!!!

Step 4: Exit the CLI

Use Ctrl+d to exit the cli.

Now your prompt should return to normal, which probably means it ends with "$" or "%".

Congratulations! You have successfully used the SQLite3 CLI.

practice-for-week-10-sql-practice-sqlite3-cli's People

Contributors

aa-assessment-project-manager[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.