I started learning programming a little bit ago and I'm doing a small desktop application. Basically it has two parts, a client's calendar (client table) and a current account for these clients (table cta_currientes) I am using MYSQL for the management of the databases: DROP DATABASE test;
CREATE DATABASE prueba;
USE prueba;
CREATE TABLE clientes (
id_cliente INT AUTO_INCREMENT NOT NULL,
nombre VARCHAR (50) NOT NULL,
telefono INT NOT NULL,
direccion varchar (50),
observaciones varchar (150),
PRIMARY KEY (id_cliente)
);
CREATE TABLE cta_corriente (
id_cta INT AUTO_INCREMENT NOT NULL,
id_cliente INT NOT NULL,
debe INT,
haber INT,
PRIMARY KEY (id_cta),
FOREIGN KEY (id_cliente) REFERENCES clientes(id_cliente)
);
I have these two tables, the question is: how can I make the FK of the table cta_current be automatically assigned when I insert a client in the client table (so that when inserting a client the pk of that table, automatically assign the FK of the cta_current table) ??
Since already if I did not post correctly (try to find in Google the solution or something similar and do not succeed), I appreciate the patience to my query. Thank you very much.