Question about PostgreSQL [b]SERIAL[/b] Numeric Data Type
Posted: Sat Aug 14, 2004 8:58 pm
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?
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?
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
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));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');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