-3
-- 1 --
create database clinica;
use clinica;
-- 2 --
create table ambulatorio(
idnroa int(15) unsigned not null auto_increment,
andar int(15) not null,
capacidade smallint(45) not null,
primary key (idnroa)
);
create table medicos(
idcodm int(15) unsigned not null auto_increment,
idnroa int(15) unsigned not null ,
nome varchar(40) not null,
idade smallint(15) not null,
especialidade char(20) not null,
cpf numeric(11) not null,
cidade varchar(30) not null,
nroa int(15) not null,
primary key (idcodm),
foreign key (idnroa) references ambulatorio (idnroa)
);
create table pacientes(
idcodp int(15) unsigned not null auto_increment,
nome varchar(40) not null,
idade smallint(15) not null,
cidade char(30) not null,
cpf numeric(11) not null,
primary key (idcodp)
);
create table funcionarios(
idcodf int(15) unsigned not null auto_increment,
nome varchar(40) not null,
idade smallint (15) not null,
cpf numeric(11) not null,
cidade varchar(30) not null,
salario numeric(10) not null,
primary key (idcodf)
);
create table consultas(
data date not null,
hora time not null,
idcodm int(15) not null,
idcodp int(15) not null,
foreign key (idcodm) references medicos (idcodm),
foreign key (idcodp) references pacientes (idcodp)
);
Do you have any?
– rray
Always put the COMPLETE ERROR, so it facilitates searches.
– Guilherme Nascimento
Why don’t you use Workbench to create the tables and keys, I don’t see the
CONSTRAINT
, it seems that tried to make in hand the modeling.– Guilherme Nascimento
@clear you tested my answer? Because I ran the full command and ran error-free in my bank. If it works, accept the answer as valid.
– Eduardo Mendes