Está en la página 1de 10

Creamos la BD práctica 3

Y las tablas fabricante y articulo.

A.
B.

C.
D.

E.

F.
G.

H.

I.

J.
K.

L.

M.
N.

O.

P.
Q.

R.
S.

T.

create database practica3;


use practica3;

create table fabricante(


clave_fabricante int identity primary key,
nombre varchar (30),
);

create table articulo(


clave_articulo int identity primary key,
nombre varchar (30),
precio int,
clave_fabricante int foreign key references
fabricante(clave_fabricante)
);

select*from fabricante,articulo;

select*from articulo;

insert into fabricante(nombre)values('Kingston');


insert into fabricante(nombre)values('Adata');
insert into fabricante(nombre)values('Logintech');
insert into fabricante(nombre)values('Lexar');
insert into fabricante(nombre)values('Seagate');
insert into articulo
(nombre,precio,clave_fabricante)values('Teclado',100,3);
insert into articulo (nombre,precio,clave_fabricante)values('Disco
duro 300GB',500,5);
insert into articulo
(nombre,precio,clave_fabricante)values('Mouse',80,3);
insert into articulo (nombre,precio,clave_fabricante)values('Memoria
USB',140,4);
insert into articulo (nombre,precio,clave_fabricante)values('Memoria
RAM',290,1);
insert into articulo (nombre,precio,clave_fabricante)values('Disco
duro extraible 250 Gb',650,5);
insert into articulo (nombre,precio,clave_fabricante)values('Memoria
USB',279,1);
insert into articulo (nombre,precio,clave_fabricante)values('DVD
Rom',450,2);
insert into articulo (nombre,precio,clave_fabricante)values('CD
Rom',200,2);
insert into articulo (nombre,precio,clave_fabricante)values('Tarjeta
de red',180,3);

--a
select*from articulo;

--b
select nombre from articulo;

--c
select nombre,precio from articulo;

--d
select distinct nombre from articulo;

--e
select*from articulo where clave_articulo=5;

--f
select*from articulo where nombre='Teclado';

--g
select*from articulo where nombre='Memoria RAM' or nombre='Memoria
USB';

--h
select*from articulo where nombre like 'M%';

--i
select*from articulo where precio=100;

--j
select*from articulo where precio >200;

--k
select*from articulo where precio between 100 and 350;

--l
select AVG(precio)from articulo;

--m
select AVG(precio)from articulo where clave_fabricante=2;
--n
select*from articulo order by nombre;

--o
select*from articulo order by precio desc;

--p
select nombre,precio from articulo where precio >250 order by precio
desc,nombre asc;

--q
select*from articulo, fabricante;

--r
select clave_articulo,articulo.nombre,fabricante.nombre from
articulo,fabricante;

--s
select fabricante.nombre,articulo.nombre,precio from
fabricante,articulo where fabricante.nombre='Logintech' order by
articulo.nombre;

--t
select articulo.nombre,precio,fabricante.nombre from
articulo,fabricante where fabricante.nombre='Lexar' or
fabricante.nombre='Kingston' order by precio desc;

--u
insert into articulo(nombre,precio,clave_fabricante) values
('Altavoces',120,2);

--v

También podría gustarte