Untitled
unknown
plain_text
9 months ago
1.8 kB
8
Indexable
create database BIBLIOTECA;
use BIBLIOTECA;
create table USUARIOS(
COD int primary key auto_increment,
NOMBRE varchar(100) not null,
TLF varchar(15) unique, /* */
EMAIL varchar(120),
DISTRITO varchar(25),
OBSERVACIONES mediumtext,
key(DISTRITO)
);
insert into USUARIOS(NOMBRE,TLF,EMAIL,DISTRITO) values
('PEDRO','+346432567','pedro@pedrito.es','Carabanchel'),
('PAMELA','+346484567','pedro@pedrito.es','Hortaleza'),
('Ana','+349832567','pedro@pedrito.es','Carabanchel');
select * from USUARIOS;
/*
Primary key - que el valor sea unico, no pueden haber nulos, solo una primary key, es agrupado hace la mejor busqueda
Unique key - es valor unico, puede ser nulo, puede haber mas de un solo unique key, no es un indice de referencia avanzada
Key/Index - No es un valor unico, puede ser nulo, puede haber mas de un solo key, no es agrupado pero si es un indice de busqueda
*/
create table LIBROS(
COD int primary key auto_increment,
TITULO varchar(100) not null,
ISBN varchar(12) unique not null,
GENERO varchar(20) not null,
PAGINAS int not null,
KEY (GENERO)
);
insert into LIBROS(TITULO,ISBN,GENERO,PAGINAS) values
('La historia interminable','239851205','Novela Fantastica','352'),
('Momo','547253623','Novela Fantastica','125'),
('El Silmarilion','99348514','Novela Epica','232');
select * from LIBROS;
create table PRESTAMOS(
CODUSU int not null,
CODLIB int not null,
FECHAPRES timestamp default current_timestamp,
FECHADEVO date,
DIASPENALIZA int,
OBSERVACIONES mediumtext,
foreign key (CODUSU) references USUARIOS(COD)
on delete cascade
on update cascade,
foreign key (CODLIB) references LIBROS(COD)
on delete cascade
on update cascade
);
insert into PRESTAMOS(CODUSU,CODLIB) values
(1,2),
(1,1),
(3,3);
select * from PRESTAMOS;
drop table PRESTAMOSEditor is loading...
Leave a Comment