2
Eai personal, to create an SQL for Insert in related tables, are the following tables:
tb_Customer(id_Customer INTEGER [PK], nm_Customer VARCHAR, cpf_cnpj NUMERIC)
dm_address_type(cd_address_type CHAR(1) [PK], ds_address_type VARCHAR)
tb_customer_address(id_customer [PFK], cd_address_type CHAR(1)[PFK], street VARCHAR, lot INTEGEER, references VARCHAR, zip_code VARCHAR)
SELECT * FROM dm_address_type
cd_address_type: R , C , O
ds_address_type: Residencial, Comercial, Outros
My question is the following, to register the client 'JOAZINHO' would be the following SQL?:
Joãozinho Silva - 888,777,666-55
Residential Address: Rua das Flores, 1. CEP: 01234-567 Commercial address: Rua das Pedras, 100 Conjunto 200. CEP: 01234-567
INSERT INTO tb_Customer(nm_customer, cpf_cnpj) VALUES ("Jãozinho Silva", "888.777.666-55")
SET @ic_Customer = LAST_INSERT_ID()
INSERT INTO tb_customer_address(street, lot, references, zip_code, id_customer, cd_address_type) values ('Rua das Flores', '1', 'references', 01234-567', @id_Customer, 'R')
INSERT INTO tb_customer_address(street, lot, references, zip_code, id_customer, cd_address_type) values ('Rua das Pedras', '100 Conjunt 200', 'references', 01234-567', @id_Customer, 'C')
And another question is how many different addresses can I register for each customer? How many needed, right?
Vlww personal. Hug!
What is the database manager: Mysql or SQL Server?
– José Diz
Mysql, but it differs a lot the use of Insert? VLW
– Matheus Klemann