CSE 414 Homework 1: SQLITE

Objectives:
To be able to create and manipulate tables in sqlite3.
Assignment tools:
SQLite 3
Due date:
Wednesday, April 8 by 11:00pm. Turn in your solution using the assignment drop box linked from the main course web page.
What to turn in:
A file containing all of your SQL and SQLite commands, and SQL comments for your responses that are not in SQL. No need to include any inputs nor outputs.

Motivation: We will use SQLite for this assignment. SQLite is a software library that implements a SQL database engine. We will use SQLite in this assignment because it offers an extremely lightweight method to create and analyze structured datasets (by structured we mean datasets in the form of tables rather than, say, free text). Using SQLite is a minimal hassle approach to realizing the benefits of a relational database management system. Of course, SQLite does not do everything, but we will get to that point in later assignments. In the meantime, you can also check a page that describes when to use SQLite and when not to use it.

Extra Resources :

Assignment Details:

To run SQLite do the following:

(see how easy it is to get started!)
  1. [25 points] First, create a simple table using the following steps:
    1. Create a table R(A,B) where both A and B are integers.
    2. Insert the tuples (2,4), (1,1), (3,2)
    3. Write a SQL statement that returns all tuples
    4. Now insert the tuple ('5','2'). Do you get an error? Why?
    5. Write a SQL statement that returns only column A for all tuples
    6. Write a SQL statement that returns all tuples where A<=B

For the next question you will be asked to create tables with attributes of types integer, varchar, date, and Boolean. However, SQL Lite does not have date and Boolean: you will use varchar and int instead:

  1. [10 points] Create a table called MyRestaurants with the following attributes:
  2. [10 points] Insert at least five tuples using the SQL INSERT command five (or more) times. You should insert at least one restaurant you liked, at least one restaurant you did not like, and at least one restaurant where you leave the iLike field NULL.

  3. [10 points] Write a SQL query to return all restaurants in your table.
  4. [15 points] Now experiment with a few of SQLite's output formats using the SQL query you wrote for question 4:
    1. print the results in comma-separated form
    2. print the results in list form, delimited by " | "
    3. print the results in column form, and make each column have width 15
    4. for each of the formats above, try printing/not printing the column headers with the results
  5. [15 points] Modify your SQL query such that it prints "I liked it" or "I hated it" for each restaurant you liked or not. Note that you are not allowed to modify the table on disk. You should be able to answer this question using only a SELECT statement, although you may need to look in the sqlite documentation for some ideas about how to do it. A solution that creates and uses an extra table, howerver, will be accepted.
  6. [15 points] Write a SQL query that returns all restaurants that you like, but have not visited since more than 3 months ago.