Create a database, call it restaurant. In your terminal: createdb restaurant
createdb restaurant
Write a database schema: create a restaurant.sql file, in it write a CREATE TABLE statement to create a table called restaurant. This table will contain the following information, you will use the appropriate data types to represent the info. Please use an auto-incrementing primary key ID:
- name
- distance (in miles from HeadQuarters)
- stars
- category (type of food)
- favorite dish
- does takeout?
- last time you ate there
- Run your file one of two ways:
- Copy the "CREATE TABLE" statement and paste it into the PostgreSQL shell
- psql restaurant -f restaurant.sql
If the table has been created successfully, you should see "CREATE TABLE" being printed. You can also describe the table schema in the shell using the \d command:
restaurant=# \d restaurant
Write INSERT statements to enter data into the restaurant table. You can paste the statements into the psql shell.
Write queries to get
- The names of the restaurants that you gave a 5 stars to
- The favorite dishes of all 5-star restaurants
- The the id of a restaurant by a specific restaurant name, say 'Moon Tower'
- restaurants in the category of 'BBQ'
- restaurants that do take out
- restaurants that do take out and is in the category of 'BBQ'
- restaurants within 2 miles
- restaurants you haven't ate at in the last week
- restaurants you haven't ate at in the last week and has 5 stars