Primary Key with serial

Started by x asasaxaxabout 18 years ago4 messagesgeneral
Jump to latest
#1x asasaxax
xanaruto@gmail.com

Hi,

I have the following table create table product(cod serial, user_cod
bigint, constraint product_fk Foreign Key(user_cod) references user(cod),
constraint product_pk Primary Key(cod, user_cod));

What i want to happend is that:
user_cod cod
1 1
1 2
1 3
2 1
3 1
3 2

Can serial do that? If not, what can i do to make this happen?

Thanks a lot

#2brian
brian@zijn-digital.com
In reply to: x asasaxax (#1)
Re: Primary Key with serial

x asasaxax wrote:

Hi,

I have the following table create table product(cod serial, user_cod
bigint, constraint product_fk Foreign Key(user_cod) references user(cod),
constraint product_pk Primary Key(cod, user_cod));

What i want to happend is that:
user_cod cod
1 1
1 2
1 3
2 1
3 1
3 2

Can serial do that?

No, a serial type will always be unique.

If not, what can i do to make this happen?

Re-evaluate your schema. Why do you want these two columns to have such
a relationship? If it's very important, don't use a serial for cod and
have your application figure out the value to assign.

b

#3Berend Tober
btober@ct.metrocast.net
In reply to: x asasaxax (#1)
Re: Primary Key with serial

x asasaxax wrote:

I have the following table create table product(cod serial, user_cod
bigint, constraint product_fk Foreign Key(user_cod) references user(cod),
constraint product_pk Primary Key(cod, user_cod));

What i want to happend is that:
user_cod cod
1 1
1 2
1 3
2 1
3 1
3 2

Can serial do that? ...

No.

...what can i do to make this happen?

http://archives.postgresql.org/pgsql-general/2006-08/msg00744.php

#4x asasaxax
xanaruto@gmail.com
In reply to: Berend Tober (#3)
Re: Primary Key with serial

can anyone do a example for me.. an explain how it works?

Thanks a lot

2008/3/29, Berend Tober <btober@ct.metrocast.net>:

Show quoted text

x asasaxax wrote:

I have the following table create table product(cod serial,

user_cod

bigint, constraint product_fk Foreign Key(user_cod) references

user(cod),

constraint product_pk Primary Key(cod, user_cod));

What i want to happend is that:
user_cod cod
1 1
1 2
1 3
2 1
3 1
3 2

Can serial do that? ...

No.

...what can i do to make this happen?

http://archives.postgresql.org/pgsql-general/2006-08/msg00744.php