Re: herencia y key

From: Anthony Sotolongo <asotolongo(at)gmail(dot)com>
To: Hibiki <npolanco(at)uij(dot)edu(dot)cu>, 'Ayuda' <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: herencia y key
Date: 2017-04-10 14:28:58
Message-ID: 1d30b742-5ffb-3d8b-dcc6-d7d6372e56aa@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Hola, te comento entre lineas algunas cosas ,pero dependerá un poco del
nivel de exclusividad que tengas en la relacion de la herencia

On 10/04/17 12:08, Hibiki wrote:
> Hola a todos, me gustaría que me aclararan una duda, cuando yo creo una tabla madre y dos hijas, ejemplo:
>
> CREATE TABLE public.persona
> (
> id serial,
> ci character varying(11) NOT NULL,
> nombre name NOT NULL,
> age integer NOT NULL,
> sexo_id integer NOT NULL
> );
>
> CREATE TABLE public.cliente
> (
> -- Inherited from table persona: id serial,
> -- Inherited from table persona: ci character varying(11) NOT NULL,
> -- Inherited from table persona: nombre name NOT NULL,
> -- Inherited from table persona: age integer NOT NULL,
> -- Inherited from table persona: sexo_id integer NOT NULL,
> tipo_cliente_id integer NOT NULL
> )
> INHERITS (public.persona)
> );
>
> CREATE TABLE public.programador
> (
> -- Inherited from table persona: id serial,
> -- Inherited from table persona: ci character varying(11) NOT NULL,
> -- Inherited from table persona: nombre name NOT NULL,
> -- Inherited from table persona: age integer NOT NULL,
> -- Inherited from table persona: sexo_id integer NOT NULL,
> tipo_programador_id integer NOT NULL,
> vincula_laboral boolean
> )
> INHERITS (public.persona)
> );
>
>
> A) Las relaciones con otras tablas, es decir las llaves foráneas, que son comunes las tengo que hacer:
> 1- Solo en la tabla madre.
> 2- En cada una de las tablas hijas.
> 3- O en las tres tablas, en la madre y ratificarla en cada hija.
si la tabla madre esta vacía, es suficiente tener las FK en las
hijas, si no estas seguro que tu tabla madre esta vacía, vas a tener que
declarar las FK en las 3

>
> B) La llave primaria la creo:
> 1- Las 3 tablas.
> 2- Solo en la madre.
> 3- O solo en las hijas.
idem a lo anterior

> C) Sería la PK de tipo serial en las 3 tablas o alguna combinación de integer en una/unas y serial en otra/otras?
>
a tu necesidad o gusto

> Gracias desde ya.
>
> Saludos
>
>
>
> -
> Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda(at)postgresql(dot)org)
> Para cambiar tu suscripci�n:
> http://www.postgresql.org/mailpref/pgsql-es-ayuda

-
Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda(at)postgresql(dot)org)
Para cambiar tu suscripcin:
http://www.postgresql.org/mailpref/pgsql-es-ayuda

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Anthony Sotolongo 2017-04-10 14:45:45 Re: herencia y key
Previous Message mauricio pullabuestan 2017-04-10 14:02:11 Re: Replicar base de datos con Postgres-BDR