Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/07/2014, 07:26
educdd
 
Fecha de Ingreso: octubre-2012
Ubicación: Madrid
Mensajes: 67
Antigüedad: 11 años, 6 meses
Puntos: 1
Crear una tabla con multiples claves foraneas

Buenas

Me gustaría poder crear una tabla que tenga más de un campo que sean claves foráneas. He visto un montón de ejemplos pero teniendo solo un campo como clave foránea.

Quiero que tanto el idTipoCliente como el idPais de la tabla de cliente sean claves foraneas de sus respectivas tablas...


Código:
CREATE TABLE tipoCliente (
	id int PRIMARY KEY AUTO_INCREMENT NOT NULL,
	tipoCliente varchar(25) NOT NULL UNIQUE,
	codigoCliente varchar(25),
	descripcion varchar(60))
	ENGINE=InnoDB;

CREATE TABLE pais (
	id int PRIMARY KEY AUTO_INCREMENT NOT NULL,
	nombre varchar(25) NOT NULL UNIQUE,
	descripcion varchar(60))
	ENGINE=InnoDB;

CREATE TABLE cliente (
	id int PRIMARY KEY AUTO_INCREMENT NOT NULL,
	nombre varchar(25) NOT NULL,
	apellido1 varchar(25) NOT NULL,
	apellido2 varchar(25) NOT NULL,
	idPais int,
	email varchar(40) NOT NULL UNIQUE,
	idTipoCliente int NOT NULL,
	FOREIGN KEY (idTipoCliente) REFERENCES tipoCliente (id)
    	ON DELETE RESTRICT ON UPDATE CASCADE)
	ENGINE=InnoDB;
Alguien podría ayudarme??