0% found this document useful (0 votes)
9 views3 pages

Datos Tablas

The document contains SQL statements that create tables, insert data, and write queries on a database with tables for components, suppliers, articles, and shipments. The tables are related with foreign keys. Data is inserted and selected from the tables.

Uploaded by

vel231529
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Datos Tablas

The document contains SQL statements that create tables, insert data, and write queries on a database with tables for components, suppliers, articles, and shipments. The tables are related with foreign keys. Data is inserted and selected from the tables.

Uploaded by

vel231529
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

insert into proveedores values('P1','Carlos',20,'Sevilla'),

('P2','Juan',10,'Madrid'),
('P3','Jose',30,'Sevilla'),
('P4','Inma',20,'Sevilla'),
('P5','Eva',30,'Caceres')

insert into componentes values('C1','X3A','Rojo',12,'Sevilla'),


('C2','B85','Verde',17,'Madrid'),
('C3','C4B','Azul',17,'Malaga'),
('C4','C4B','Rojo',14,'Sevilla'),
('C5','VT8','Azul',12,'Madrid'),
('C6','C30','Rojo',19,'Sevilla')

insert into articulos values('T1','Clasificador','Madrid'),


('T2','Perforadora','Malaga'),
('T3','Lectora','Caceres'),
('T4','Consola','Caceres'),
('T5','Mezcladora','Sevilla'),
('T6','Terminal','Barcelona'),
('T7','Cinta','Sevilla')

insert into envios values('P1','C1','T1',200),


('P1','C1','T4',700),
('P2','C3','T1',400),
('P2','C3','T2',200),
('P2','C3','T3',200),
('P2','C3','T4',500),
('P2','C3','T5',600),
('P2','C3','T6',400),
('P2','C3','T7',600),
('P2','C5','T2',100),
('P3','C3','T1',200),
('P3','C4','T2',500),
('P4','C6','T3',300),
('P4','C6','T7',300),
('P5','C2','T2',200),
('P5','C2','T4',100),
('P5','C5','T5',500),
('P5','C5','T7',100),
('P5','C6','T2',200),
('P5','C1','T4',100),
('P5','C3','T4',200),
('P5','C4','T4',800),
('P5','C5','T4',400),
('P5','C6','T4',500)

create table DB_SQL1.dbo.componentes (


C# varchar(3) primary key,
cnombre varchar(20) not null,
color varchar(10) not null,
peso numeric(4,0),
ciudad varchar (30)
);
create table DB_SQL1.dbo.proveedores (
P# varchar (3) primary key,
pnombre varchar(20),
categoria numeric(4,0),
ciudad varchar(30)
);
create table DB_SQL1.dbo.articulos (
T# varchar(3) primary key,
tnombre varchar(20),
ciudad varchar(30)
);
create table DB_SQL1.dbo.envios (
P# varchar(3),
C# varchar(3),
T# varchar(3),
constraint FK_3 foreign key (P#) references DB_SQL1.dbo.proveedores
(P#),
constraint FK_2 foreign key (C#) references
DB_SQL1.dbo.componentes (C#),
constraint FK_1 foreign key (T#) references
DB_SQL1.dbo.componentes (T#),
cantidad numeric (5,0),
);

insert into proveedores values('P1','Carlos',20,'Sevilla'),


('P2','Juan',10,'Madrid'),
('P3','Jose',30,'Sevilla'),
('P4','Inma',20,'Sevilla'),
('P5','Eva',30,'Caceres')

insert into componentes values('C1','X3A','Rojo',12,'Sevilla'),


('C2','B85','Verde',17,'Madrid'),
('C3','C4B','Azul',17,'Malaga'),
('C4','C4B','Rojo',14,'Sevilla'),
('C5','VT8','Azul',12,'Madrid'),
('C6','C30','Rojo',19,'Sevilla')

insert into articulos values('T1','Clasificador','Madrid'),


('T2','Perforadora','Malaga'),
('T3','Lectora','Caceres'),
('T4','Consola','Caceres'),
('T5','Mezcladora','Sevilla'),
('T6','Terminal','Barcelona'),
('T7','Cinta','Sevilla')

insert into envios values('P1','C1','T1',200),


('P1','C1','T4',700),
('P2','C3','T1',400),
('P2','C3','T2',200),
('P2','C3','T3',200),
('P2','C3','T4',500),
('P2','C3','T5',600),
('P2','C3','T6',400),
('P2','C3','T7',600),
('P2','C5','T2',100),
('P3','C3','T1',200),
('P3','C4','T2',500),
('P4','C6','T3',300),
('P4','C6','T7',300),
('P5','C2','T2',200),
('P5','C2','T4',100),
('P5','C5','T5',500),
('P5','C5','T7',100),
('P5','C6','T2',200),
('P5','C1','T4',100),
('P5','C3','T4',200),
('P5','C4','T4',800),
('P5','C5','T4',400),
('P5','C6','T4',500)

select * from articulos

select P.P#,P.pnombre from proveedores P

select C.C#,C.cnombre , C.ciudad from componentes C


where C.C# = 'c3'

select P#,pnombre,categoria
from proveedores
order by pnombre asc,categoria desc

select C#, COUNT(C#)


from envios
group by C#

select * from componentes

select C#,count(C#) as cant_C,sum(cantidad)as total


from envios
group by C#

select P#, COUNT(P#) as cant_c


from DB_SQL1.dbo.envios
group by P#
having COUNT(P#)<=10 and count(P#)>=8

select * from componentes

You might also like