jueves, 21 de abril de 2016

Tabla que relaciona dos tablas SQL

La tabla user_authority relaciona las tablas usuario y authority

CREATE TABLE usuario
(
  id integer NOT NULL,
  username character varying(50) NOT NULL,
  password character varying(100) NOT NULL,
  CONSTRAINT user_pkey PRIMARY KEY (id)
);

CREATE TABLE authority
(
  id integer NOT NULL,
  name character varying(50) NOT NULL,
  CONSTRAINT authority_pkey PRIMARY KEY (id)
);

CREATE TABLE user_authority
(
  user_id integer NOT NULL,
  authority_id integer NOT NULL,
  CONSTRAINT fk_authority_id_user_authority FOREIGN KEY (authority_id)
      REFERENCES authority (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fk_usuario_user_authority FOREIGN KEY (user_id)
      REFERENCES usuario (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
);

No hay comentarios:

Publicar un comentario