SQL (MAria DB), preciso que alguem me ajuda acorrigir esse esquema fĆ­sico a baixo | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

SQL (MAria DB), preciso que alguem me ajuda acorrigir esse esquema fĆ­sico a baixo

create database hospital; use hospital; create table hospital ( cĆ³d int primary key, endereƧo char(70) not null, nome char(70), cidade char(70) not null, cep int ); create table paciente ( cpf int not null primary key, nome char(70) not null, sexo varchar(1) not null, medicamento char(20) not null ); create table quartos(num int not null primary key,andar char(2),qtde_pacientes int); create table receita_medica(nome_remedio char(20) not null primary key,funcionalidade char(15) not null,doenƧa char(50)not null); create table medico_paciente(data_consulta date not null); create table medico(cpf int not null primary key,nome char(70) not null,sexo char(1) not null,estado char(2) not null,endereƧo char(40) not null,especialidade char(20) not null,num int); alter table quartos add cpf_paciente int; alter table quartos add foreign key fokquartos(cpf_paciente) references paciente(cpf); alter table paciente add cĆ³dhospital char(60); alter table paciente add foreign key fkpaciente(cĆ³dhospital) references hospital(cĆ³d); alter table receita_medica add cpf_paciente int; alter table receita_medica add foreign key fkreceita_medica(cpf_paciente) references paciente(cpf); alter table medico_paciente add cpf_paciente int; alter table medico_paciente add foreign key fkmedico_paciente(cpf_paciente) references paciente(cpf); alter table medico add cpf_medico int; alter table medico add foreign key fkmedico(cpf_medico) references medico(cpf); alter table hospital add cpf_paciente int; alter table hospital add foreign key fkhospital(cpf_paciente) references hospital(cpf);

21st Nov 2017, 9:54 PM
Ɓlvarosmalm
Ɓlvarosmalm - avatar
4 Respostas
+ 3
se tu estĆ” criando a tabela, por quĆŖ estĆ” alterando as mesmas e adicionando Fks, quando for criar a tabela, jĆ” insere as Fks
3rd Dec 2017, 5:31 PM
kernelpanic_r
kernelpanic_r - avatar
+ 3
e outra, o campo cpf terĆ” 11 nĆŗmeros, creio que int aceita atĆ© 9 nĆŗmeros, utiliza um long
3rd Dec 2017, 5:32 PM
kernelpanic_r
kernelpanic_r - avatar
+ 3
o Id da tabela, Ć© melhor por um incremento automĆ”tico, para nĆ£o ter que fazer manualmente
3rd Dec 2017, 5:34 PM
kernelpanic_r
kernelpanic_r - avatar
0
pow, obrigado, me ajudou e consegui fazer aqui, sou um pouco iniciante ainda
3rd Dec 2017, 6:56 PM
Ɓlvarosmalm
Ɓlvarosmalm - avatar