English version (when available)
insert into T1 values (1,10,100); -- a insert into T1 values (NULL,20,NULL); -- b falla insert into T1 values (2,20,NULL); -- c insert into T1 values (3,NULL,300); -- d insert into T2 values (2,NULL,NULL); -- e falla insert into T2 values (2,20,NULL); -- f insert into T1 values (1,20,200); -- g falla insert into T2 values (4,10,100); -- h falla insert into T2 values (2,30,230);-- i
update T1 set a=2 where a=1; -- j falla update T1 set a=5 where a=1; -- k update T2 set e=220 where d=20; -- l update T2 set a=5 where d=20; -- m update T2 set a=2,d=10,e=100 where d=20; -- n update T1 set a=6,b=60,c=600 where a=2; -- o falla update T1 set a=7,b=70,c=700 where a=3; -- p update T2 set a=7 where d=10; -- q update T2 set a=7 where d=30; -- r update T1 set a=6,b=60,c=600 where a=2; -- s
delete from T2 where d=30; -- t delete from T1 where a=7; -- u falla delete from T1 where a=5; -- v delete from T2 where d=10; -- w delete from T1 where a=7; -- x ahora sí delete from T1 where a=6; -- yEl resultado final debe ser las 2 tablas vacías de filas.
a) delete from T1 where a = 3; -- sin problema b) delete from T1 where a = 2; -- no ha hecho nada, en T2 hay 2 filas que hacen referencia a la que pretendemos borrar -- la solución es, si realmente queremos borrar esa fila: delete from T2 where a = 2; delete from T1 where a = 2; -- Es decir, eliminar antes las filas de T2 enlazadas.
select sip, apellidos, nombre, fecha_nacimiento from paciente where fecha_nacimiento between '1978-03-03' and '1978-04-30' order by fecha_nacimiento;Solución alternativa:select sip, apellidos, nombre, fecha_nacimiento from paciente where fecha_nacimiento >= '1978-03-03' and fecha_nacimiento <= '1978-04-30' order by 4;
select sip, apellidos, nombre, fecha_nacimiento from paciente where fecha_nacimiento NOT between '1978-03-03' and '1978-04-30' order by fecha_nacimiento;Solución alternativa:select sip, apellidos, nombre, fecha_nacimiento from paciente where fecha_nacimiento < '1978-03-03' or fecha_nacimiento > '1978-04-30' order by 4;
select apellidos, nombre, provincia from paciente where apellidos like 'Martínez %'
select apellidos, nombre, provincia from paciente where nombre like 'Jos%'
select apellidos, nombre, provincia from paciente where nombre like 'JOSE %'Hemos dejado un espacio al final de "JOSE" para eliminar a los JOSEP y similares. No obstante, dependiendo de cómo se hayan almacenado estos valores, la solución puede ser más o menos precisa.
select distinct provincia from paciente where provincia like '%CA%' or provincia like '%ON%'
select distinct provincia from paciente where provincia like '%CA%' and provincia like '%ER%'
select distinct provincia from paciente where provincia like '%AL%' and provincia like '%I%'Solución alternativa:select distinct provincia from paciente where provincia like '%AL%I%' or provincia like '%I%AL%'
select distinct provincia from paciente where provincia like '%AL%I%'
select distinct provincia from paciente where provincia like '%A_I%'
select distinct provincia from paciente where provincia not like 'A%' order by provincia;