Advertisement
Guest User

si

a guest
Sep 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 7.93 KB | None | 0 0
  1. create database Consultorio2
  2.  
  3. use Consultorio2;
  4.  
  5. -- Tablas Principales
  6.  
  7.  
  8. create table odontologo(
  9.     ciOdon int not null primary key,
  10.     nombre varchar(64) not null,
  11.     sexo char not null,
  12.     telefono int not null,
  13.     idAgenda int not null foreign key references agenda(idAgenda)
  14.         on update cascade
  15.         on delete cascade,
  16.     idUsuario int not null foreign key references usuario(idUsuario)
  17.         on update cascade
  18.         on delete cascade
  19. );
  20.  
  21. create table especialidad(
  22.     idEsp int not null  primary key,
  23.     descripcion varchar(64) not null
  24. );
  25.  
  26. create table servicio(
  27.     idServ int not null primary key,
  28.     nombre varchar(32) not null,
  29.     descripcion varchar (64) not null,
  30.     estado varchar(32) not null
  31. );
  32.  
  33. create table recepcionista(
  34.     ciRecep int not null primary key,
  35.     nombre varchar(64) not null,
  36.     sexo char not null,
  37.     telefono int not null,
  38.     idUsuario int not null foreign key references usuario(idUsuario)
  39.         on update cascade
  40.         on delete cascade
  41. )
  42.  
  43.  
  44. create table cita(
  45.     idCita int not null primary key,
  46.     estado varchar(32) not null,
  47.     fecha date not null,
  48.     hora time not null,
  49.    
  50.     idHist int not null,
  51.     idCon int not null,
  52.  
  53.     foreign key (idCon,idHist) references consulta(idCon,idHist)
  54.         on update cascade
  55.         on delete cascade,
  56.  
  57.     idRecep int not null foreign key references recepcionista(ciRecep)
  58.         on update cascade
  59.         on delete cascade,
  60.    
  61.     idAgenda int not null foreign key references agenda(idAgenda)
  62.     on update cascade
  63.         on delete cascade,
  64.  
  65.         ciPaci int not null foreign key references paciente(ciPaci)
  66.     on update cascade
  67.         on delete cascade
  68.  
  69.  
  70. );
  71.  
  72.  
  73. create table materia_prima(
  74.     idMatPrim int not null primary key,
  75.     nombre varchar(32) not null,
  76.     descripcion varchar(128),
  77.     estado varchar(32) not null,
  78.     stock int not null,
  79.     cant_usos int not null,
  80.     total_usos int not null
  81. );
  82.  
  83. create table horario (
  84.     idHor int not null primary key,
  85.     estado bit not null,
  86.     fecha date not null,
  87.     hora_inicio time not null,
  88.     hora_fin time not null
  89. )
  90.  
  91.  
  92. create table paciente(
  93.     ciPaci int not null primary key,
  94.     nombre varchar(64) not null,
  95.     sexo char not null,
  96.     telefono int not null,
  97.     idHist int not null foreign key references historial(idHist)
  98.         on update cascade
  99.         on delete cascade,
  100.     fecha_nacimiento date not null,
  101.     correo varchar(32) not null,
  102.     idUsuario int not null foreign key references usuario(idUsuario)
  103.         on update cascade
  104.         on delete cascade,
  105. )
  106.  
  107. create table nota_compra(
  108.     idNota int not null primary key,
  109.     nombre varchar(64) not null,
  110.     fecha date not null,
  111.     nit int not null,
  112.     monto int not null
  113. )
  114.  
  115. create table cara_dental
  116. (
  117.     idCarDent int not null primary key,
  118.     nombre varchar(32)
  119. )
  120.  
  121. -- Tablas con llaves foraneas
  122.  
  123. create table tiene_especialidad(
  124.     idOdon int not null foreign key references odontologo(ciOdon)
  125.         on update cascade
  126.         on delete cascade,
  127.     idEspe int not null foreign key references especialidad(idEsp)
  128.         on update cascade
  129.         on delete cascade,
  130.     primary key (idOdon,idEspe)
  131. )
  132.  
  133. create table ficha_serv(
  134.     idCita int not null foreign key references cita(idCita)
  135.         on update cascade
  136.         on delete cascade,
  137.     idServ int not null foreign key references servicio(idServ)
  138.         on update cascade
  139.         on delete cascade,
  140.     primary key (idCita,idServ)
  141. )
  142.  
  143.  
  144. create table agenda(
  145.     idAgenda int not null primary key,
  146.     idCita int not null foreign key references cita(idCita)
  147.         on update cascade
  148.         on delete cascade,
  149. )
  150.  
  151. create table historial(
  152.     idHist int not null primary key,
  153.     fechaRegistro date not null,
  154.     ultimaConsulta date not null
  155. )
  156.  
  157. create table consulta(
  158.     idCon int not null,
  159.     idHist int not null,
  160.     primary key(idCon,idHist),
  161.     foreign key (idHist) references historial(idHist)
  162.         on update cascade
  163.         on delete cascade,
  164.     diagnostico varchar(128) not null,
  165.     fecha_retorno date not null,
  166.     motivo varchar(128) not null,
  167.     tratamiento varchar(128) not null
  168. )
  169.  
  170. create table receta(
  171.     idRec int not null primary key,
  172.     descripcion varchar(128) not null,
  173.     idCon int not null,
  174.     idHist int not null,
  175.     foreign key (idCon,idHist) references consulta(idCon,idHist)
  176.         on update cascade
  177.         on delete cascade,
  178. )
  179.  
  180. create table odontograma(
  181.     idOdonto int not null primary key,
  182.     idHist int not null,
  183.     idCon int not null ,
  184.     foreign  key (idCon,idHist) references consulta(idCon,idHist)
  185.         on update cascade
  186.         on delete cascade,
  187. )
  188.  
  189. create table diente(
  190.     idDiente int not null,
  191.     idOdonto int not null foreign key references odontograma(idOdonto)
  192.         on update cascade
  193.         on delete cascade,
  194.     primary key (idDiente,idOdonto),
  195.     nombre varchar(64) not null,
  196.     estadoActual varchar(32) not null,
  197. )
  198.  
  199. create table serv_cons(
  200.     idServ int not null foreign key references servicio(idServ)
  201.         on update cascade
  202.         on delete cascade,
  203.     idHist int not null,
  204.     idCon  int not null,
  205.     foreign key (idCon,idHist) references consulta(idCon,idHist)
  206.         on update cascade
  207.         on delete cascade,
  208.     primary key (idServ,idHist,idCon)
  209. )
  210.  
  211. create table odont_horario(
  212.     idHor int not null foreign key references horario(idHor)
  213.         on update cascade
  214.         on delete cascade,
  215.     ciOdon int not null foreign key references odontologo(ciOdon)
  216.         on update cascade
  217.         on delete cascade,
  218.     primary key (idHor,ciOdon)
  219. )
  220.  
  221.  create table serv_mat(
  222.     cant_usos int not null,
  223.     idMatPrim int not null foreign key references materia_prima(idMatPrim)
  224.         on update cascade
  225.         on delete cascade,
  226.     idServ int not null foreign key references servicio(idServ)
  227.         on update cascade
  228.         on delete cascade,
  229.     primary key (idMatPrim,idServ)
  230.  
  231.  )
  232.  
  233.  CREATE TABLE odont_serv(
  234. ciOdon INT NOT NULL FOREIGN KEY REFERENCES odontologo(ciOdon )
  235.         on update cascade
  236.         on delete cascade,
  237. idServ INT NOT NULL FOREIGN KEY REFERENCES servicio(idServ)
  238.         on update cascade
  239.         on delete cascade,
  240. PRIMARY KEY (ciOdon,idServ)
  241. )
  242.  
  243. CREATE TABLE nota_vent
  244. (idNotaVent INT NOT NULL PRIMARY KEY,
  245.  idConsult INT NOT NULL,
  246.  idHist INT NOT NULL,
  247.  FOREIGN KEY (idConsult,idHist) REFERENCES consulta(idCon,idHist)
  248.         on update cascade
  249.         on delete cascade,
  250.  fecha DATE NOT NULL,
  251.  monto_total INT NOT NULL,
  252.  saldo INT NOT NULL
  253.  )
  254.  
  255. CREATE TABLE cuota(
  256.  idNotaVenta INT NOT NULL FOREIGN KEY REFERENCES nota_vent(idNotaVent)
  257.         on update cascade
  258.         on delete cascade,
  259.  idCuota INT NOT NULL,
  260.  PRIMARY KEY (idNotaVenta,idCuota),
  261.  ciPaci INT NOT NULL FOREIGN KEY REFERENCES paciente(ciPaci)
  262.         on update cascade
  263.         on delete cascade,
  264.  fecha DATE NOT NULL,
  265.  monto INT NOT NULL
  266.  
  267.  )
  268.  
  269.  create table rol(
  270.     idRol int not null primary key,
  271.     nombre varchar(16)
  272.  )
  273.  
  274.  create table permiso(
  275.     idPer int not null,
  276.     idRol int not null foreign key references rol(idRol)
  277.         on update cascade
  278.         on delete cascade,
  279.     primary key (idPer,idRol),
  280.  
  281.  )
  282.  
  283.   CREATE TABLE usuario (
  284.  idUsuario INT NOT NULL PRIMARY KEY,
  285.  nombre VARCHAR(20)NOT NULL,
  286.  estado bit NOT NULL,
  287.  contraseña VARCHAR(50) NOT NULL,
  288.  idNota INT NOT NULL FOREIGN KEY REFERENCES nota_Compra(idNota)
  289.         on update cascade
  290.         on delete cascade,
  291.  idRol int not null foreign key references rol(idRol)
  292.         on update cascade
  293.         on delete cascade
  294.  )
  295.  
  296.  CREATE TABLE estudio_complementario
  297.  (
  298.   idEstudio INT NOT NULL PRIMARY KEY,
  299.   nombre VARCHAR(20),
  300.   descripcion VARCHAR(128) NOT NULL,
  301.   idServicio INT NOT NULL FOREIGN KEY REFERENCES servicio(idServ)
  302.         on update cascade
  303.         on delete cascade,
  304.  
  305.  )
  306.  
  307.  
  308.  CREATE TABLE cp_dental(
  309.  idCarDent INT NOT NULL FOREIGN KEY REFERENCES cara_dental(idCarDent)
  310.         on update cascade
  311.         on delete cascade,
  312.  idDiente INT NOT NULL ,
  313.  idOdontoG INT NOT NULL,
  314.  FOREIGN KEY (idDiente,idOdontoG) REFERENCES diente(idDiente,idOdonto)
  315.         on update cascade
  316.         on delete cascade,
  317.  PRIMARY KEY (idCarDent,idDiente,idOdontoG),
  318.  estado_diagnostico VARCHAR(100) NOT NULL,
  319.  estado_tratamiento VARCHAR(100)NOT NULL
  320.  )
  321.  
  322.  CREATE TABLE nota_mat_prima(
  323.  idNota INT NOT NULL FOREIGN KEY REFERENCES nota_compra(idNota)
  324.         on update cascade
  325.         on delete cascade,
  326.  idMatPrim INT NOT NULL FOREIGN KEY REFERENCES materia_prima(idMatPrim)
  327.         on update cascade
  328.         on delete cascade,
  329.  PRIMARY KEY (idNota,idMatPrim),
  330.  Precio INT NOT NULL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement