-2
I can’t automatically increment primary and foreign keys of my tables using SERIAL, because error happens and always have to enter the key value.
create table cliente(
cd_cliente serial primary key not null,
nome varchar(50),
endereco varchar(50),
cidade varchar(50)
)
create table telefone(
cd_telefone serial primary key not null,
cd_cliente serial,
numero_telefone varchar(20),
foreign key(cd_cliente) references cliente (cd_cliente)
)
insert into cliente
values
(1, 'Pessoa1', 'Algum lugar', 'Cidade'),
(2, 'Pesso2', 'Algum lugar', 'Cidade'),
(3, 'Pessoa3', 'Algum lugar', 'Cidade')
insert into telefone
values
(1, 1, '01 1111-1111'),
(2, 2, '02 2222-2222'),
(3, 3, '03 3333-3333')
If you set the field
cd_telefone
asserial
then do not enter a value for this field or informDEFAULT
to take into account the value generated bysequence
. As has already been said it makes no sense to definetelefone.cd_cliente
asserial
since you should always inform which aware is associated with the phone.– anonimo