-
Notifications
You must be signed in to change notification settings - Fork 0
/
Notes
61 lines (36 loc) · 2.01 KB
/
Notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Things Endpoints
GET /api/things
GET /api/things/:thing_id
GET /api/things/:thing_id/reviews
Assignment Questions:
1. How are the syntaxes async and await useful when writing JavaScript code?
2. With respect to Knex, how does the transaction method relate to BEGIN and COMMIT syntax in PostgreSQL?
If, partway through the transaction, we decide we do not want to commit (perhaps we just noticed that Alice's balance went negative),
we can issue the command ROLLBACK instead of COMMIT, and all our updates so far will be canceled.
3. What is a "sequence table" in PostgreSQL?
he sequence is a special type of data created to generate unique numeric identifiers in the PostgreSQL
database. Most often used for the creation of artificial primary keys, sequences are similar but not identical
to AUTO_INCREMENT in MySQL
4. What does RESTART IDENTITY CASCADE do?
Truncate: empty a table or set of tables
RESTART IDENTITY: Automatically restart sequences owned by columns of the truncated table(s).
CASCADE: Automatically truncate all tables that have foreign-key references to any of the named
tables, or to any tables added to the group due to CASCADE.
5. What does SELECT setval('blogful_users_id_seq', 1) do?
General Question:
1. What is PostgreSQL SERIAL PRIMARY KEY?"
First, create a sequence object and set the next value generated by the sequence as the default value for the column.
Second, add a NOT NULL constraint to the id column because a sequence always generates an integer, which is a non-null value.
Third, assign the owner of the sequence to the id column; as a result, the sequence object is deleted when the id column or table is dropped
3
CREATE TABLE table_name(
id SERIAL
); equals ....
This:
CREATE SEQUENCE table_name_id_seq;
CREATE TABLE table_name (
id integer NOT NULL DEFAULT nextval('table_name_id_seq')
);
ALTER SEQUENCE table_name_id_seq
OWNED BY table_name.id;
2.