Sei sulla pagina 1di 7

/* Razziel Clemente Vidales Pea */

drop database if exists agenda_musical;


create database agenda_musical;
use agenda_musical;
set autocommit=0;
/*
if exists(select 1 from sys.sysforeignkey where role='FK_BAJA') then
alter table BAJA
delete foreign key FK_BAJA
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_CANCIONES') then
alter table CANCIONES
delete foreign key FK_CANCIONES
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_LISTA_REPRODUCCION') th
en
alter table LISTA_REPRODUCCION
delete foreign key FK_LISTA_REPRODUCCION
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_USUARIOS') then
alter table USUARIOS
delete foreign key FK_USUARIOS
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_CREA_USU') then
alter table CREA_USU
delete foreign key FK_CREA_USU
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_PERSONAS') then
alter table PERSONAS
delete foreign key FK_PERSONAS
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_CREA') then
alter table CREA
delete foreign key FK_CREA
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_PERTENECE') then
alter table PERTENECE
delete foreign key FK_PERTENECE
end if;
*/
/*==============================================================*/
/* Table: BAJA
*/
/*==============================================================*/
drop table if exists BAJA;
create table BAJA
(
ID_USU
smallint
not null,
ID_CANCION
integer
not null,

constraint PK_BAJA primary key clustered (ID_USU, ID_CANCION)


);
/*==============================================================*/
/* Table: CANCIONES
*/
/*==============================================================*/
drop table if exists CANCIONES;
create table CANCIONES
(
ID_CANCION
integer
not null,
NOM_CANCION
Varchar(30)
not null,
DURACION
time
not null,
AUTOR
varchar(15)
null,
FECHA
date
null,
GENERO
varchar(13)
null,
ESTATUS_CANCION
bit
not null,
constraint PK_CANCIONES primary key clustered (ID_CANCION)
);
/*==============================================================*/
/* Table: CREA
*/
/*==============================================================*/
drop table if exists CREA;
create table CREA
(
ID_LISTA
integer
not null,
ID_USU
smallint
not null,
constraint PK_CREA primary key clustered (ID_LISTA, ID_USU)
);
/*==============================================================*/
/* Table: CREA_USU
*/
/*==============================================================*/
drop table if exists CREA_USU;
create table CREA_USU
(
ID_USU
smallint
not null,
NO_CONTROL
char(8)
not null,
constraint PK_CREA_USU primary key clustered (ID_USU, NO_CONTROL)
);
/*==============================================================*/
/* Table: LISTA_REPRODUCCION
*/
/*==============================================================*/
drop table if exists LISTA_REPRODUCCION;
create table LISTA_REPRODUCCION
(
ID_LISTA
integer
not null,
NOM_LISTA
varchar(40)
not null,
ESTATUS_LISTA
bit
not null,
constraint PK_LISTA_REPRODUCCION primary key clustered (ID_LISTA)
);
/*==============================================================*/
/* Table: PERSONAS
*/
/*==============================================================*/
drop table if exists PERSONAS;
create table PERSONAS
(
NO_CONTROL
char(8)
not null,

NOM_PER
varchar(40)
not null,
APE_PAT_PER
varchar(15)
not null,
APE_MAT_PER
varchar(15)
not null,
E_MAIL
varchar(40)
not null,
ESTATUS_PER
bit
not null,
FECHA_NAC
date
null,
constraint PK_PERSONAS primary key clustered (NO_CONTROL)
);
/*==============================================================*/
/* Table: PERTENECE
*/
/*==============================================================*/
drop table if exists PERTENECE;
create table PERTENECE
(
ID_CANCION
integer
not null,
ID_LISTA
integer
not null,
ORDEN
tinyint
null,
constraint PK_PERTENECE primary key clustered (ID_CANCION, ID_LISTA)
);
/*==============================================================*/
/* Table: USUARIOS
*/
/*==============================================================*/
drop table if exists USUARIOS;
create table USUARIOS
(
ID_USU
smallint
not null,
NOM_USU
varchar(15)
not null,
PASSWORD
varchar(40)
not null,
ESTATUS_USU
bit
not null,
constraint PK_USUARIOS primary key clustered (ID_USU)
);
set autocommit=0;
/*==============================================================*/
/* INSERTAR EN TABLA USUARIOS
*/
insert into USUARIOS(ID_USU,NOM_USU,PASSWORD,ESTATUS_USU)
values (1,
'usu1',
'abc123',
1),
(2,
'usu2',
'bcd123',
(3,
'usu3',
'cde123',
(4,
'usu4',
'def123',
(5,
'usu5',
'efg123',
(6,
'usu6',
'fgh123',
(7,
'usu7',
'ghi123',
(8,
'usu8',
'hij123',
(9,
'usu9',
'ijk123',
(10,
'usu10',
'jkl123',
1);
commit;

0),
1),
0),
1),
1),
1),
1),
0),

/*==============================================================*/
/* INSERTAR EN TABLA PERSONAS
*/
insert into PERSONAS (NO_CONTROL,NOM_PER,APE_PAT_PER,APE_MAT_PER,E_MAIL,FECHA_NA
C,ESTATUS_PER)
values (11590111,
'anayeli',
'otero',

'ugalde',

'ana@gmail.com',
0,
0),
(11590112,
'berenice',
s',
'chavez',
'bere@gmail.com',
(11590113,
'cristina',
ez',
'aguilar',
'cristina@gmail.com', 0,1),
(11590114,
'antonio',
'palacio',
'antonio@gmail.com',
0,0),
(11590115,
'guadalupe',
'bravo',
'lupe@gmail.com',
0,1),
(11590116,
'ricardo',
,
'ramirez',
'ricardo@gmail.com',
(11590117,
'jose',
',
'ortega',
'molina@gmail.com',
(11590118,
'patricia',
'salazar',
'patricia@gmail.com', 0,1),
(11590119,
'antonio',
ez',
'hernandez',
'antonio@gmail.com',
0,1),
(11590110,
'Razziel',
',
'Pea',
'razziel@gmail.com',
commit;

'barcena
0,1),
'hernand
'ruiz',
'moreno',
'molina'
0,1),
'jimenez
0,0),
'lopez',
'hernand
'Vidales
0,1);

/*==============================================================*/
/* INSERTAR EN TABLA CANCIONES
*/
insert into CANCIONES (ID_CANCION,NOM_CANCION,GENERO,AUTOR,DURACION,FECHA,ESTATU
S_CANCION)
values (1,
'dont worry be happy',
'pop',
'BOBBY MCFERRIN',
000315, 20111002,
1),
(2,
'Seen The Rain',
'pop',
'Creedence',
000237, 19981003,
1),
(3,
'Lovers On The Sun',
'house',
'David Guetta',
000323, 20140802,
1),
(4,
'Shot Me Down',
'house',
'David Guetta',
000310, 20140802,
1),
(5,
'Bad',
'house',
'David Guetta',
000250, 20140802,
1),
(6,
'Pan y Mantequilla',
'pop',
'Efecto pasillo',
000323, 20101017,
1),
(7,
'Que Sera de mi vida',
'pop',
'Gibson brothers',
000353, 19820308,
1),
(8,
'Instant Crush',
'house',
'Daft punk',
000535, 20140711,
1),
(9,
'Animals',
'electro',
'Martin Garrix',
000311, 20140525,
1),
(10,
'Youre The One That I Want',
'rock po
p',
'Grease',
000310, 19810112,
1);
commit;
/*==============================================================*/
/* INSERTAR EN TABLA LISTA_REPRODUCCION
*/

insert into LISTA_REPRODUCCION (ID_LISTA,NOM_LISTA,ESTATUS_LISTA)


values (1,
'lista1',
1),
(2,
'lista1',
1),
(3,
'lista1',
1),
(4,
'lista1',
1),
(5,
'lista1',
1),
(6,
'lista1',
1),
(7,
'lista1',
1),
(8,
'lista1',
1),
(9,
'lista1',
1),
(10,
'lista1',
1);
commit;
/*==============================================================*/
/* INSERTAR EN TABLA CREA_USU

*/

insert into CREA_USU (NO_CONTROL,ID_USU)


values (11590110,
1),
(11590111,
2),
(11590112,
3),
(11590113,
4),
(11590114,
5),
(11590115,
6),
(11590116,
7),
(11590117,
8),
(11590118,
9),
(11590119,
10);
commit;
/*==============================================================*/
/* INSERTAR EN TABLA CREA

*/

insert into CREA (ID_USU,ID_LISTA)


values (1,
1),
(2,
2),
(3,
3),
(4,
4),
(5,
5),
(6,
6),
(7,
7),
(8,
8),
(9,
9),
(10,10);
commit;
/*==============================================================*/
/* INSERTAR EN TABLA BAJA
insert into BAJA (ID_USU,ID_CANCION)
values (1,
1),
(2,
2),
(3,
3),
(4,
4),
(5,
5),
(6,
6),
(7,
7),
(8,
8),
(9,
9),
(10,10);

*/

commit;
/*==============================================================*/
/* INSERTAR EN TABLA PERTENECE

*/

insert into PERTENECE (ID_LISTA,ID_CANCION,ORDEN)


values (1,
1,
1),
(2,
2,
3),
(3,
3,
4),
(4,
4,
2),
(5,
5,
8),
(6,
6,
9),
(7,
7,
7),
(8,
8,
6),
(9,
9,
5),
(10,10,10);
commit;
/*==============================================================*/
/* ELIMINAR DATOS DE TABLAS
Delete from
commit;
Delete from
commit;
Delete from
commit;
Delete from
commit;
Delete from
commit;
Delete from
commit;
Delete from
commit;
Delete from
commit;

*/

PERSONAS;
USUARIOS;
LISTA_REPRODUCCION;
CANCIONES;
CREA_USU;
CREA;
BAJA;
PERTENECE;

/*==============================================================*/
/* Consulta
*/
select nom_per, ape_pat_per, ape_mat_per
from personas, crea_usu, crea, lista_reproduccion
where personas.no_control=crea_usu.no_Control and crea_usu.id_usu=crea.id_usu
and crea.id_lista=lista_reproduccion.id_lista
group by nom_per
having (
select count(baja.id_cancion)
from canciones, baja, pertenece
where canciones.id_cancion=baja.id_cancion and baja.id_cancion=pertenece.id_canc
ion)>2;
/*==============================================================*/
/* Privilegios
*/
Grant insert,delete
Grant insert,delete,update

on PERSONAS to 'usu_n1';
on USUARIOS to 'usu_n1';

Grant
Grant
Grant
Grant
Grant
Grant

select,insert,delete,update
select,insert,delete
insert
insert
insert
select,insert,update

on LISTA_REPRODUCCION to 'usu_n1';
on CANCIONES to 'usu_n1';
on CREA_USU to 'usu_n1';
on CREA to 'usu_n1';
on BAJA to 'usu_n1';
on PERTENECE to 'usu_n1';

Grant
Grant
Grant
Grant
Grant
Grant
Grant
Grant

select,insert,delete
select,insert,update
select,insert,delete,update
select,insert,delete
select,insert
select,insert
select,insert
select,insert,update

on PERSONAS to 'usu_n2';
on USUARIOS to 'usu_n2';
on LISTA_REPRODUCCION to 'usu_n2';
on CANCIONES to 'usu_n2';
on CREA_USU to 'usu_n2';
on CREA to 'usu_n2';
on BAJA to 'usu_n2';
on PERTENECE to 'usu_n2';

Grant
Grant
Grant
Grant
Grant
Grant
Grant
Grant

ALL
ALL
ALL
ALL
ALL
ALL
ALL
ALL

on
on
on
on
on
on
on
on

PERSONAS to 'usu_n3';
USUARIOS to 'usu_n3';
LISTA_REPRODUCCION to 'usu_n3';
CANCIONES to 'usu_n3';
CREA_USU to 'usu_n3';
CREA to 'usu_n3';
BAJA to 'usu_n3';
PERTENECE to 'usu_n3';

Potrebbero piacerti anche