Bases de Datos - Consultas

 
Vista:

Consultas

Publicado por Hannibal (1 intervención) el 23/11/2009 23:20:50
alter table ingreso add constraint cod_ing_pk primary key (cod_ing);

alter table autor alter column nacionalidad_aut set default 'Colombiano';

alter table autor add column fecha_nac_aut date;

insert into autor (cedula_aut, nombre_aut, apellido_aut, fecha_nac_aut, nacionalidad_aut) values ('004', 'Gabriel', 'Garcia', '2009-08-06', default), ('005','andres Manuel','Lopez Diaz','1752-08-06',default), ('006','Albert','Einstein','1872','Alemania');

update autor set nacionalidad_aut = default where cedula_aut='006';

update autor set nombre_aut='Moises' where cedula_aut='001';

update autor set (nacionalidad_aut, apellido_aut)=('alemania','Jimenez') where cedula_aut = '006' and nombre_aut = 'Albert';

insert into medico values ('HSV 01', 'Miguel Cadena', '310000000', 'Otorrinolaringologo');

select * from libro where id_est=(select id_est from estanteria where numero_est='434')
select * from libro where id_lib=(select id_lib from autlib where ced_aut = (select cedula_aut from autor where nombre_aut='gabriel'));

Select * from autor where extract (year from fecha_nac_aut) = 2007 and extract (month from fecha_nac_aut) = 08;

select * from autor where (to_char(fecha_nac_aut, 'yyyy')='2007') and (to_char(fecha_nac_aut, 'mm')='08');

select * from libro where id_est = (select id_est from estanteria where (numero_est = '4902' and lugar_est = 'C-45') );

select * from editorial where id_edi =(select id_edi from libro where id_lib = (select id_lib from autlib where ced_aut = (select cedula_aut from autor where nombre_aut = 'gabriel' )));

alter table ingreso add constraint ing_med_fk foreign key (cod_med) references medico (cod_med);

alter table paciente add constraint cod_pac_pk primary key (cod_pac);
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Consultas

Publicado por sin nombre (2 intervenciones) el 24/11/2009 00:40:56
alter table autor add column fecha_nac_aut date; //agregar ccolumnas

alter table autor add apellido_aut varchar (100); //agregar ccolumnas

alter table autor alter column nacionalidad_aut set default “Colombiano”; // dejar un campo por defecto

insert into medico values (“HSV 01”, “Miguel Cadena”,”310000000”, “Otorrinolaringologo”); //insertar datos a las tablas

insert into autor values (“003”, “Mauricio”, “Perez”, “2007-06-09”, default); //ingresar datos con y campo por defecto

insert into autor (cedula_aut, nombre_aut, apellido_aut, fecha_nac_aut, nacionalidad_aut) values (“004”, “Gabriel”, “Garcia”, “2009-08-06”, default),
(“005”,”andres Manuel”,”Lopez Diaz”,”1752-08-06”,default),
(“006”,”Albert”,”Einstein”,”1872”,”Alemania”); // ingresar datos especificando los campos

update autor set nombre_aut=”Moises” where cedula_aut=”001”; // actualizar datos

update autor set nacionalidad_aut = default where cedula_aut=”006”; // actualizar datos dejando un campo por defecto

update autor set (nacionalidad_aut, apellido_aut)=(“alemania”,”Jimenez”)
where cedula_aut = “006” and nombre_aut = “Albert”; //actualizar varios datos

alter table centro_trabajo add constraint cen_tra_pk primary key (codigo_ct); //crear la llave primaria con el alter

select * from libro where id_lib = (select id_lib from autlib where ced_aut=(select cedula_aut from autor where nombre_aut = “Gabriel”)); //mostrar la informacion de un libro con el nombre del autor

select a.* from libro as a, autlib where autlib.ced_aut =(select cedula_aut from autor where nombre_aut =”gabriel” ) and autlib.id_lib = a.id_lib; //mostrar la informacion de un libro con el nombre del autor

select * from libro where id_est =(select id_est from estanteria where numero_est =”34”); //seleccionar la informacion de un libro con el numero de la estanteria

select * from autor where (to_char(fecha_nac_aut,”yyyy”)=”2009”) or (to_char(fecha_nac_aut,”dd”)=”06”); // seleccionar la informacion de un autor solo con el año de nacimiento

SELECT * FROM NOMBRE DE LA TABLA // Para seleccionar todos los campos de una tabla.

select nombre_aut from autor // Mostrar el nombre de todos los autores

select nombre_aut, nacionalidad_aut from autor // mostrar el nombre y la edad de todos los autores

select nombre_aut, nacionalidad_aut from autor where nombre_aut = 'pedro' // mostrar el nombre y la edad de todos los autores que se llamen pedro

select * from autor order by fecha_nac_aut // mostrar todos los autores orden ascendente, por fecha de nacimiento

select * from autor order by fecha_nac_aut desc // mostrar todos los autores orden descendente, por fecha de nacimiento

update autor set nombre_aut='juan' where nombre_aut='albert' // modificar el nombre de un autor que se llama albert por juan

select * from autor where cedula_aut = (select cedula_aut from libroautor where id_lib='1000') // Seleccione toda la informacion del autor del libro que tiene id igual a 1000.

select id_edi,titulo_lib from libro where id_usu ='1234'; // seleccionar dos campos de una tabla por medio de otro campo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Consultas

Publicado por con nombre (2 intervenciones) el 24/11/2009 00:47:35
select * from autor where (fecha_nac_aut >'2006-12-31') and (fecha_nac_aut <'2010-1-1') // decadas

select * from autor where apellido_aut like '%garcia%'; //tenga el apellido

select * from autor where upper(apellido_aut)like upper('GARCIA MARQUEZ'); // LETRAS

select * from autor where apellido_aut like '%s'; // TERMINE

select * from autor where apellido_aut like 's%'; //COMIENZA

select autor.* from usuario,autor,autlib,libro where usuario.nombre_usu='samara' and libro.id_usu=usuario.id_usu and libro.id_lib=autlib.id_lib and autlib.ced_aut=cedula_aut; //ANIDADA

select * from autor where apellido_aut like '%s%'; //que la contenga
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Consultas

Publicado por parcial (1 intervención) el 24/11/2009 03:01:26
usuarios que contengan el nombre luis

1).select * fromusuario where nombre_usu like "%luis%"; //cambiar comillas a sencillas

mostrar la informacion de todos los libros del autor qeu tiene como nombre gabriel

select a.* from libro as a, autlib where autlib.ced_aut =(select cedula_aut from autor where nombre_aut ="gabriel" ) and autlib.id_lib = a.id_lib;

mostrar los los autores nacido en 1985

select * from autor where (to_char(fecha_nac_aut,"yyyy")="1985") ;

modificar los datos de una autor nota cambiarel nombre y apellido

update autor set (nombre_aut,nacionalidad_aut, apellido_aut,fecha_nac_aut)=("nombre","colombiano","apellido","1999-1-1")
where cedula_aut = "006";

seleccionar todo la informacion de los libros que se encuentren el la estanteria 123

select * from libro where id_est="123";


insertar un registro en cada tabla: (se deben poner comillas sensillas a cada uno de los datos)

insert into usuario values(444,mario,8850145);
insert into estanteria values(333,f-45,2);
insert into editorial values(154,editf,cll 45 #85-21);
insert into autor values(007,daniel,lopez rojas,1978-04-21,colombiano);
insert into libro values(sa43-21,santillana,matematicas,154,333,444);
insert into autlib values(007,sa43-21);

mostrar los autores con la edad de mayor a menor

select * from autor order by fecha_nac_aut;

CUANTAS PREGUNTAS SON Y ESCRIBAN LA QUE HAYAN FALTA
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Consultas

Publicado por parcial2 (1 intervención) el 24/11/2009 03:27:42
mostrar toda la informacion de del autor de mayor edad

select * from autor where fecha_nac_aut=(select min(fecha_nac_aut) from autor)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar