Description
Question 1
(10 points)
Create a table dubbed rdata that has five columns: id (type serial primary key), a and b (consisting of
strings that should be no more than five characters), moment (which is a date), and x (which is a number
that should have no more than five digits total and two to the right of the decimal point).
Question 2
(10 points)
Delete the table and create it again, with certain constraints: a and b cannot be null and must be unique;
moment should have a default value of 2020-01-01 (); and x should be larger than zero.
Question 3
(10 points)
Use \d in combination with the name of your table to display its properties. Copy and paste all output here.
1
Question 4
(10 points)
Insert three rows of data into your table. Do this without explicity referring to the column id or moment.
Display your table using the command select * from rdata. You should see a default date in your moment
column!
Question 5
(10 points)
Attempt to add another row of data with a negative value for x. Show what happens. (If the row is
added. . . that’s bad. It means you don’t have the constraint x > 0 defined.) Afterwords, add a valid row of
data, and show the table.
Question 6
(10 points)
Change the table rdata so as to change the data in moment so that two of the dates are in March 2020,
while the other two are not in March 2020. Use where as shown in the notes, and utilize a logical “or” to
update two of the dates to the same date in March at the same time. Show your updated table. (Note that
the rows may be rearranged. This is OK.)
Question 7
(10 points)
Add a new column to rdata dubbed y, and let it be of boolean type with default value false. Display your
updated table.
Question 8
(10 points)
Remove the row of your table with id value 2. Display your updated table.
Question 9
(10 points)
Rename the column moment to have the name date. Display your updated table.
2