Está en la página 1de 3

CREACION DE LA BD EJEMPLO

Modicons1

Use ejemplo
Go
/*crea la tabla cliente*/
create table clientes
(num_clie integer NOT NULL,
empresa varchar(20) NOT NULL,
rep_clie integer NULL,
limite_credito decimal(10,2) NULL)
alter table clientes
add constraint PK_cli_numclie
primary key (num_clie)
go

/* crea la tabla RepVentas*/


create table RepVentas
(num_empl integer NOT NULL,
nombre varchar(15) NOT NULL,
edad integer NULL,
oficina_rep integer NULL,
titulo varchar(10) NULL,
contrato datetime NOT NULL,
director integer NULL,
cuota decimal(10,2) NULL,
ventas decimal(10,2) NOT NULL)
alter table RepVentas
add constraint PK_num_clie
primary key (num_empl)
go
/* crea la tabla oficinas, en modo comando*/

create table oficinas


(oficina integer NOT NULL,
ciudad varchar(15) NOT NULL,
region varchar(10) NOT NULL,
dir integer,
objetivo decimal(10,2),
ventas decimal(10,2) NOT NULL)
go
alter table oficinas
add constraint PK_oficina
primary key (oficina)
go

/*consulta19: crea las tablas PEDIDO y PRODUCTOS*/


create table pedidos
(num_pedido integer not null,
fecha_pedido datetime not null,
clie integer not null,
rep integer,
fab char(3) not null,
producto char(5) not null,
cant integer not null,
importe decimal(10,2) not null)
go
alter table pedidos
add constraint PK_num_pedido
primary key (num_pedido)
go

create table productos


(id_fab char(3) not null,
id_producto char(5) not null,
descripci�n varchar(20) not null,
precio decimal(10,2) not null,
existencias integer not null)
go
alter table productos
add constraint PK_fab_prod
primary key (id_fab,id_producto)
go

Modicons2

insert into clientes (num_clie,empresa,rep_clie,limite_credito)values


(2102,'First Corp.',101,65000)
insert into clientes(num_clie,empresa,rep_clie,limite_credito) values
(2103,'American Systems',105,50000)
insert into clientes (num_clie,empresa,rep_clie,limite_credito)values
(2107,'Ace International',110,35000)
insert into clientes (num_clie,empresa,rep_clie,limite_credito)values
(2111,'ABC Systems',103,50000)
insert into clientes (num_clie,empresa,rep_clie,limite_credito)values
(2123,'AsgComp.Asoc.',102,40000)
insert into RepVentas values (101,'Raul ',40,1,'Ingeniero','12/12/2003',106,2000,0)
insert into RepVentas values (102,'julio',20,2,'Arquit. ','06/12/2003',106,3000,0)
insert into RepVentas values (103,'Silvia',20,1,'Sicologa','05/12/2003',101,1000,0)
insert into RepVentas values
(104,'Andres',18,3,'Periodist.','07/12/2004',102,2000,0)
insert into RepVentas values (105,'Cesar',40,2,'Administ','15/12/2003',106,1000,0)
insert into RepVentas values (106,'Ana',60,3,'Abogada','30/11/2003',102,500,0)
insert into RepVentas values (110,'Elba',60,2,'Profesora','20/12/2003',106,1000,0)
insert into oficinas values (1,'Lima','Lima',101,1,10000)
insert into oficinas values (2,'junin','Junin',106,2,50000)
insert into oficinas values (3,'Trujillo','Trujillo',102,3,60000)
insert into pedidos values (1,'12/12/2004',2102,103,'101','A1',10,100)
insert into pedidos values (2,'15/12/2004',2103,105,'101','A2',5,25)
insert into pedidos values (3,'12/12/2004',2102,104,'101','A1',2,20)
insert into productos values ('101','A1','balde',10,100)
insert into productos values ('101','A2','jarra',5,100)
insert into productos values ('102','B1','lapiz',2,100)

Modicons3

Use ejemplo
go
alter table clientes
add constraint fk_cli_repventas
foreign key (rep_clie)
references RepVentas(num_empl)
go
alter table RepVentas
add constraint FK_Dir_RepVentas
foreign key(director)
references RepVentas(num_empl)
go
alter table pedidos
add constraint FK_FabPro_Productos
foreign key (fab,producto)
references productos(id_fab,id_producto)
go
alter table pedidos
add constraint FK_Rep_RepVentas
foreign key (rep)
references RepVentas(num_empl)
go
alter table oficinas
add constraint FK_Direc_RepVentas
foreign key (dir)
references RepVentas(num_empl)

alter table RepVentas


add constraint FK_Ofi_Oficinas
foreign key (oficina_rep)
references oficinas(oficina)

También podría gustarte