Which one of the following ways would you use in declaring Primary Keys by Postgres?
#1
CREATE TABLE user(
user_id PRIMARY KEY,
...
)
#2
CREATE TABLE user(
user_id NOT NULL,
...
CONSTRAINT user_pk PRIMARY KEY(user_id);
)
Which one of the following ways would you use in declaring Primary Keys by Postgres?
CREATE TABLE user(
user_id PRIMARY KEY,
...
)
CREATE TABLE user(
user_id NOT NULL,
...
CONSTRAINT user_pk PRIMARY KEY(user_id);
)
I would use method #1.
One reason to use method #2 is if your primary key were to span more than one column. In that case, method #1 won't work because it only supports a single column primary key.