0
I recently started to study a little mysql, and decided to create a table of registered here in the club that I am part.
Create database Clube
default character set utf8
default collate utf8_general_ci;
use Clube;
create table Cadastrados(
Nome varchar(50),
Sexo enum('M', 'F'),
Matricula varchar(9),
Curso enum('Arquitetura e Urbanismo', 'Engenharia Ambiental', 'Engenharia Civil', 'Engenharia de Controle e Automação', 'Engenharia de Minas', 'Engenharia de Produção', 'Engenharia Geológica', 'Engenharia Mecânica', 'Engenharia Metalúrgica', 'Outro'),
Endereco varchar(50),
CPF varchar(15),
RG varchar(15),
Aniversario date,
Email varchar(30),
Telefone varchar(20),
Socio enum('SIM', 'NÃO'),
Atleta enum('SIM', 'NÃO'),
Treinador enum('SIM', 'NÃO'),
primary key (Matricula)
)default charset = utf8;
So far so good. I managed to create the table, I used the insert into
to add values and test the fields, but now that my doubts begin:
In the column "Athlete", one registered can have up to 5 modalities. How I would make it work?
At first I thought about creating another table and using the Enum command to solve the problem.
Create table Atletas(
Modalidade1 enum('Atletismo', 'Basquete', 'Futebol de Campo', 'Futsal', 'Futebol Americano', 'Handebol', 'Natação'),
Modalidade2 enum('Atletismo', 'Basquete', 'Futebol de Campo', 'Futsal', 'Futebol Americano', 'Handebol', 'Natação'),
Modalidade3 enum('Atletismo', 'Basquete', 'Futebol de Campo', 'Futsal', 'Futebol Americano', 'Handebol', 'Natação'),
Modalidade4 enum('Atletismo', 'Basquete', 'Futebol de Campo', 'Futsal', 'Futebol Americano', 'Handebol', 'Natação'),
Modalidade5 enum('Atletismo', 'Basquete', 'Futebol de Campo', 'Futsal', 'Futebol Americano', 'Handebol', 'Natação')
)default charset = utf8;
And then try to connect the two tables.
But I’m finding this medium very "pig". Until because when I add something with the insert into
, I can’t modify it after, nor even put the default value as empty.
In my opinion you would have to create a table with the modalities, and another being the relationship enters the modality table and your registered athlete
– sir_ask
You could change athlete for modality use as foreign key, and connect in another table, and in the other table will have a foreign key of the registration id in question along with the modality that it uses. I don’t know if it’s clear, if you have any questions just ask ^^
– rods