Está en la página 1de 3

create database EMPRESA

go
use EMPRESA
go
create table AREA
(id_area int primary key identity (1,1)

CREATE TABLE AREA


id_area char (6) not null unique,
CONSTRAINT PK_AREA PRIMARY KEY (id_area))
go

create table EMPLEADO


(id_empleado INT not null unique,
id_area char (6) not null unique,
nom_empleado varchar (40) not null unique,
cedula varchar (40) not null,
CONSTRAINT PK_empleado PRIMARY KEY (id_empleado);
alter table empleado add constraint fk1_empleado_area
foreign key(id_area) references area (id_area))
go

create table CENTRO_COSTO


(id_centro_costo INT not null unique,
cedula varchar(40) not null,
CONSTRAINT PK_CENTRO_COSTO PRIMARY KEY (id_centro_costo);
alter table centro costo add constraint fk1_centro_costo_empleado
foreign key(cedula) references empleado (cedula))

go

create table PROVEEDOR


(id_proveedor INT not null unique,
CONSTRAINT PK_PROVEEDOR PRIMARY KEY (id_proveedor))
go

create table SOLICITUD


(num_sol INT not null unique,
fecha_sol integer unique,
rubro_sol varchar(50) not null unique,
total integer not null,
cedula varchar (40) not null,

CONSTRAINT PK_SOLICITUD PRIMARY KEY (num_sol);


alter table solicitud add constraint fk1_solicitud_empleado
foreign key(cedula) references empleado (cedula))
go

create table COTIZACION


(id_cotizacion INT not null unique,
id_proveedor INT not null unique,
num_sol INT not null unique,
num_cot integer not null,
CONSTRAINT PK_COTIZACION PRIMARY KEY (id_cotizacion);

alter table cotizacion add constraint fk1_cotizacion_proveedor


foreign key(id_proveedor) references proveedor (id_proveedor);
alter table cotizacion add constraint fk2_cotizacion_solicitud
foreign key(num_sol) references proveedor (num_sol))
go

create table OC
(num_oc INT not null unique,
id_proveedor INT not null unique,
total integer not null,
fecha_orden integer unique,
fecha_entrega integer unique,

CONSTRAINT PK_OC PRIMARY KEY (num_oc);

alter table OC add constraint fk1_OC_proveedor


foreign key(id_proveedor) references proveedor (id_proveedor)

alter table OC add constraint fk2_OC_solicitud


foreign key(total) references empleado (total))
go

create table ENTRADA


(num_entrada INT not null unique,

CONSTRAINT PK_ENTRADA PRIMARY KEY (num_entrada))

create table BIEN


(cod_bien INT not null unique,
nombre varchar(40) not null unique,
unimed integer not null,
precio integer not null,

CONSTRAINT PK_BIEN PRIMARY KEY (codigo_bien);


CONSTRAINT CK_Precio CHECK (Precio_bien>0))
go

create table ENTRADA


(num_entrada INT not null unique,

CONSTRAINT PK_ENTRADA PRIMARY KEY (num_entrada))

create table BIEN SOLICITUD


(num_sol INT not null unique,
cod_bien INT not null unique,
cant integer not null,
sub_total integer not null unique)
go
create table BIEN SALIDA
(num_salida INT not null unique,
cod_bien INT not null unique,
cantentr integer not null unique)
go

create table SALIDA


(num_salida INT not null unique,
cedula varchar (40) not null,
num_entrada INT not null unique,
fecha_entrega integer unique,
fecha_salida integer unique,
CONSTRAINT PK_SALIDA PRIMARY KEY (num_salida);

alter table salida add constraint fk1_salida_empleado


foreign key(cedula) references empleado (cedula);

alter table salida add constraint fk2_salida_entrada


foreign key(num_entrada) references entrada (num_entrada);

alter table salida add constraint fk3_salida_oc


foreign key(fecha_entrega) references oc (fecha_entrega))

También podría gustarte