Question about PostgreSQL [b]SERIAL[/b] Numeric Data Type

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

Question about PostgreSQL [b]SERIAL[/b] Numeric Data Type

Post by myleow »

Hello,

I am trying to understand the Serial type, please give me as much information as possible.

I am creating a simple table with column user_id, first_name, and last_name. I need user_id to be unique for each record so user_id can be a primary key. It would be great if it can increment itself everytime i add a new user.

So is this correct?

Code: Select all

CREATE TABLE user (user_id SERIAL PRIMARY KEY, first_name VARCHAR(40), last_name VARCHAR(40));
It should give me what i want, right?

If i add stuff into the user table, the user_id should increment by itself, right?

WHat is the insert statement like?

is it?

Code: Select all

INSERT INTO user (first_name, last_name) VALUES ('Mian', 'Leow');
When i drop the table and recreate the same, would the serial reset from 1?

If i delete any of the entries, the serial data won't be affected right? If i have 1,2,3 data and delete 1 and 2. Next insertion will have user_id =4, right?

Thank you in advance

Regards
Mian
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

Post by myleow »

no one use Postgresql?
ody
Forum Contributor
Posts: 147
Joined: Sat Mar 27, 2004 4:42 am
Location: ManchesterUK

Post by ody »

you answered all your own questions :wink:
Post Reply