Vous êtes sur la page 1sur 12

Query - /****** Objeto:

base de

Page #1

/****** Objeto: base de datos EmpresaTarea fecha de la secuencia de comandos: 12/08/2012 19:56:57 ******/ IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'EmpresaTarea') DROP DATABASE [EmpresaTarea] GO CREATE DATABASE [EmpresaTarea] ON (NAME = N'EmpresaTarea_Data', FILENAME = N'C:\Servidor SQL\Empresa Tarea_Data.MDF' , SIZE = 2, FILEGROWTH = 10%) LOG ON (NAME = N'EmpresaTarea_Log', FILENAME = N'C:\Ser vidor SQL\EmpresaTarea_Log.LDF' , SIZE = 1, FILEGROWTH = 10%) GO exec sp_dboption N'EmpresaTarea', N'autoclose', N'true' GO exec sp_dboption N'EmpresaTarea', N'bulkcopy', N'false' GO exec sp_dboption N'EmpresaTarea', N'trunc. log', N'true' GO exec sp_dboption N'EmpresaTarea', N'torn page detection', N'true' GO exec sp_dboption N'EmpresaTarea', N'read only', N'false' GO exec sp_dboption N'EmpresaTarea', N'dbo use', N'false' GO exec sp_dboption N'EmpresaTarea', N'single', N'false' GO exec sp_dboption N'EmpresaTarea', N'autoshrink', N'true' GO exec sp_dboption N'EmpresaTarea', N'ANSI null default', N'false' GO exec sp_dboption N'EmpresaTarea', N'recursive triggers', N'false' GO exec sp_dboption N'EmpresaTarea', N'ANSI nulls', N'false' GO exec sp_dboption N'EmpresaTarea', N'concat null yields null', N'false' GO exec sp_dboption N'EmpresaTarea', N'cursor close on commit', N'false' GO exec sp_dboption N'EmpresaTarea', N'default to local cursor', N'false' GO exec sp_dboption N'EmpresaTarea', N'quoted identifier', N'false' GO exec sp_dboption N'EmpresaTarea', N'ANSI warnings', N'false' GO exec sp_dboption N'EmpresaTarea', N'auto create statistics', N'true' GO exec sp_dboption N'EmpresaTarea', N'auto update statistics', N'true' GO use [EmpresaTarea] GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_ProductoBodegaStock_Bodegas] ') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[ProductoBodegaStock] DROP CONSTRAINT FK_ProductoBodegaStock_Bodegas GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_OrdenCompra_Empleado]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[OrdenCompra] DROP CONSTRAINT FK_OrdenCompra_Empleado GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Sucursales_Empresa]') and OB JECTPROPERTY(id, N'IsForeignKey') = 1)

Query - /****** Objeto:

base de

Page #2

ALTER TABLE [dbo].[Sucursales] DROP CONSTRAINT FK_Sucursales_Empresa GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Producto_ParametroProducto]' ) and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[Producto] DROP CONSTRAINT FK_Producto_ParametroProducto GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_DevolucionesDetalle_Producto Historico1]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[DevolucionesDetalle] DROP CONSTRAINT FK_DevolucionesDetalle_ProductoHistorico1 GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_FacturaDeCompraDetalles_Prod uctoHistorico]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[FacturaDeCompraDetalles] DROP CONSTRAINT FK_FacturaDeCompraDetalles_ProductoHistor ico GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_AnticiposProveedores_Proveed or]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[AnticiposProveedores] DROP CONSTRAINT FK_AnticiposProveedores_Proveedor GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_FacturaDeCompra_Proveedor]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[FacturaDeCompra] DROP CONSTRAINT FK_FacturaDeCompra_Proveedor GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_OrdenCompra_Proveedor]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[OrdenCompra] DROP CONSTRAINT FK_OrdenCompra_Proveedor GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_DevolucionesDetalle_Producto ]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[DevolucionesDetalle] DROP CONSTRAINT FK_DevolucionesDetalle_Producto GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_FacturaDeCompraDetalles_Prod ucto]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[FacturaDeCompraDetalles] DROP CONSTRAINT FK_FacturaDeCompraDetalles_Producto GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_OrdenDeCompraDetalles_Produc to]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[OrdenDeCompraDetalles] DROP CONSTRAINT FK_OrdenDeCompraDetalles_Producto GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_ProductoBodegaStock_Producto ]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[ProductoBodegaStock] DROP CONSTRAINT FK_ProductoBodegaStock_Producto GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_FacturaDeCompra_Sucursales]' ) and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[FacturaDeCompra] DROP CONSTRAINT FK_FacturaDeCompra_Sucursales GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_OrdenCompra_Sucursales]') an d OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[OrdenCompra] DROP CONSTRAINT FK_OrdenCompra_Sucursales GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Devoluciones_FacturaDeCompra ]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[Devoluciones] DROP CONSTRAINT FK_Devoluciones_FacturaDeCompra GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_FacturaDeCompraDetalles_Fact uraDeCompra]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[FacturaDeCompraDetalles] DROP CONSTRAINT FK_FacturaDeCompraDetalles_FacturaDeCompr a GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_OrdenDeCompraDetalles_OrdenC ompra]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[OrdenDeCompraDetalles] DROP CONSTRAINT FK_OrdenDeCompraDetalles_OrdenCompra GO

Query - /****** Objeto:

base de

Page #3

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_DevolucionesDetalle_Devoluci ones]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[DevolucionesDetalle] DROP CONSTRAINT FK_DevolucionesDetalle_Devoluciones GO /****** Objeto: tabla [dbo].[DevolucionesDetalle] fecha de la secuencia de comandos: 12/08/2012 19 :57:00 ******/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DevolucionesDetalle]') and OBJE CTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[DevolucionesDetalle] GO /****** Objeto: tabla [dbo].[Devoluciones] fecha de la secuencia de comandos: 12/08/2012 19:57:00 ******/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Devoluciones]') and OBJECTPROPE RTY(id, N'IsUserTable') = 1) drop table [dbo].[Devoluciones] GO /****** Objeto: tabla [dbo].[FacturaDeCompraDetalles] fecha de la secuencia de comandos: 12/08/201 2 19:57:00 ******/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FacturaDeCompraDetalles]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[FacturaDeCompraDetalles] GO /****** Objeto: tabla [dbo].[OrdenDeCompraDetalles] fecha de la secuencia de comandos: 12/08/2012 19:57:00 ******/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[OrdenDeCompraDetalles]') and OB JECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[OrdenDeCompraDetalles] GO /****** Objeto: tabla [dbo].[FacturaDeCompra] fecha de la secuencia de comandos: 12/08/2012 19:57: 00 ******/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FacturaDeCompra]') and OBJECTPR OPERTY(id, N'IsUserTable') = 1) drop table [dbo].[FacturaDeCompra] GO /****** Objeto: tabla [dbo].[OrdenCompra] fecha de la secuencia de comandos: 12/08/2012 19:57:00 * *****/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[OrdenCompra]') and OBJECTPROPER TY(id, N'IsUserTable') = 1) drop table [dbo].[OrdenCompra] GO /****** Objeto: tabla [dbo].[ProductoBodegaStock] fecha de la secuencia de comandos: 12/08/2012 19 :57:00 ******/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProductoBodegaStock]') and OBJE CTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[ProductoBodegaStock] GO /****** Objeto: tabla [dbo].[AnticiposProveedores] fecha de la secuencia de comandos: 12/08/2012 1 9:57:00 ******/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AnticiposProveedores]') and OBJ ECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[AnticiposProveedores] GO /****** Objeto: tabla [dbo].[Producto] fecha de la secuencia de comandos: 12/08/2012 19:57:00 **** **/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Producto]') and OBJECTPROPERTY( id, N'IsUserTable') = 1) drop table [dbo].[Producto] GO /****** Objeto: tabla [dbo].[Sucursales] fecha de la secuencia de comandos: 12/08/2012 19:57:00 ** ****/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sucursales]') and OBJECTPROPERT Y(id, N'IsUserTable') = 1) drop table [dbo].[Sucursales] GO /****** Objeto: tabla [dbo].[Bodegas] fecha de la secuencia de comandos: 12/08/2012 19:57:00 ***** */ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Bodegas]') and OBJECTPROPERTY(i d, N'IsUserTable') = 1) drop table [dbo].[Bodegas]

Query - /****** Objeto: GO

base de

Page #4

/****** Objeto: tabla [dbo].[Ciudad] fecha de la secuencia de comandos: 12/08/2012 19:57:00 ****** / if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Ciudad]') and OBJECTPROPERTY(id , N'IsUserTable') = 1) drop table [dbo].[Ciudad] GO /****** Objeto: tabla [dbo].[Empleado] fecha de la secuencia de comandos: 12/08/2012 19:57:00 **** **/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Empleado]') and OBJECTPROPERTY( id, N'IsUserTable') = 1) drop table [dbo].[Empleado] GO /****** Objeto: tabla [dbo].[Empresa] fecha de la secuencia de comandos: 12/08/2012 19:57:00 ***** */ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Empresa]') and OBJECTPROPERTY(i d, N'IsUserTable') = 1) drop table [dbo].[Empresa] GO /****** Objeto: tabla [dbo].[Parametro] fecha de la secuencia de comandos: 12/08/2012 19:57:00 *** ***/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Parametro]') and OBJECTPROPERTY (id, N'IsUserTable') = 1) drop table [dbo].[Parametro] GO /****** Objeto: tabla [dbo].[ParametroProducto] fecha de la secuencia de comandos: 12/08/2012 19:5 7:00 ******/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ParametroProducto]') and OBJECT PROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[ParametroProducto] GO /****** Objeto: tabla [dbo].[ProductoHistorico] fecha de la secuencia de comandos: 12/08/2012 19:5 7:00 ******/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProductoHistorico]') and OBJECT PROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[ProductoHistorico] GO /****** Objeto: tabla [dbo].[Proveedor] fecha de la secuencia de comandos: 12/08/2012 19:57:00 *** ***/ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Proveedor]') and OBJECTPROPERTY (id, N'IsUserTable') = 1) drop table [dbo].[Proveedor] GO /****** Objeto: inicio de sesin BUILTIN\Administradores fecha de la secuencia de comandos: 12/08/2 012 19:56:57 ******/ exec sp_addsrvrolemember N'BUILTIN\Administradores', sysadmin GO /****** Objeto: usuario dbo fecha de la secuencia de comandos: 12/08/2012 19:56:58 ******/ /****** Objeto: tabla [dbo].[Bodegas] fecha de la secuencia de comandos: 12/08/2012 19:57:01 ***** */ CREATE TABLE [dbo].[Bodegas] ( [Codigo] [int] NOT NULL , [CodigoBodega] [varchar] (50) NOT NULL , [NombreBodega] [varchar] (50) NOT NULL , [SucursalCodigo] [bigint] NOT NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[Ciudad] fecha de la secuencia de comandos: 12/08/2012 19:57:01 ****** / CREATE TABLE [dbo].[Ciudad] ( [Codigo] [numeric](10, 0) NOT NULL , [CodigoCiudad] [nvarchar] (13) NULL , [Nombre] [nvarchar] (60) NULL , [Zona] [nvarchar] (33) NULL , [Pais] [numeric](18, 0) NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[Empleado] **/ fecha de la secuencia de comandos: 12/08/2012 19:57:01 ****

Query - /****** Objeto:

base de

Page #5

CREATE TABLE [dbo].[Empleado] ( [Codigo] [numeric](10, 0) NOT NULL , [CodigoEmpleado] [nvarchar] (13) NULL , [Cedula] [nvarchar] (20) NULL , [Sexo] [numeric](10, 0) NULL , [ApellidosNombres] [nvarchar] (120) NULL , [Cargo] [numeric](10, 0) NULL , [Departamento] [numeric](10, 0) NULL , [Area] [numeric](10, 0) NULL , [TipoSangre] [numeric](10, 0) NULL , [CiudadDomicilio] [numeric](10, 0) NULL , [DireccionDomicilio] [nvarchar] (119) NULL , [Telefonos] [nvarchar] (20) NULL , [Nacionalidad] [numeric](10, 0) NULL , [Observacion] [nvarchar] (350) NULL , [SucursalCodigo] [bigint] NOT NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[Empresa] fecha de la secuencia de comandos: 12/08/2012 19:57:01 ***** */ CREATE TABLE [dbo].[Empresa] ( [Codigo] [int] NOT NULL , [CiudadCodigo] [numeric](10, 0) NULL , [NombreCortoEmpresa] [nvarchar] (120) NULL , [NombreLargoEmpresa] [nvarchar] (120) NULL , [DireccionCiudadOficina] [nvarchar] (120) NULL , [RUC] [nvarchar] (20) NULL , [Telefonos] [nvarchar] (15) NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[Parametro] ***/ CREATE TABLE [dbo].[Parametro] ( [Codigo] [int] NOT NULL , [Nombre] [varchar] (120) NULL ) ON [PRIMARY] GO fecha de la secuencia de comandos: 12/08/2012 19:57:01 ***

/****** Objeto: tabla [dbo].[ParametroProducto] 7:01 ******/ CREATE TABLE [dbo].[ParametroProducto] ( [CodigoLinea] [numeric](10, 0) NOT NULL , [NombreLinea] [nvarchar] (60) NULL , [SucursalCodigo] [bigint] NOT NULL ) ON [PRIMARY] GO

fecha de la secuencia de comandos: 12/08/2012 19:5

/****** Objeto: tabla [dbo].[ProductoHistorico] fecha de la secuencia de comandos: 12/08/2012 19:5 7:02 ******/ CREATE TABLE [dbo].[ProductoHistorico] ( [Codigo] [numeric](10, 0) NOT NULL , [Factura] [bigint] NULL , [OrdenCompra] [bigint] NULL , [Item] [int] NOT NULL , [ProductoCodigo] [bigint] NULL , [CantidadIngreso] [numeric](24, 4) NULL , [CantidadEgreso] [numeric](24, 4) NULL , [SaldoUnidades] [numeric](24, 4) NULL , [CostoUnitario] [numeric](24, 4) NULL , [ValorCostoPromedio] [numeric](24, 4) NULL , [Observacion] [nvarchar] (450) NULL , [SucursalCodigo] [bigint] NOT NULL , [CodigoBodega] [int] NOT NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[Proveedor] fecha de la secuencia de comandos: 12/08/2012 19:57:02 *** ***/ CREATE TABLE [dbo].[Proveedor] ( [Codigo] [numeric](10, 0) NOT NULL , [CodigoProveedor] [nvarchar] (20) NULL , [ApellidosNombres] [nvarchar] (250) NULL , [CiudadProveedor] [numeric](10, 0) NULL , [Direccion] [nvarchar] (120) NULL , [Ruc] [nvarchar] (20) NULL , [Telefonos] [nvarchar] (15) NULL , [Observacion] [nvarchar] (350) NULL , [SucursalCodigo] [bigint] NOT NULL ,

Query - /****** Objeto:

base de

Page #6

[AutorizacionSRI] [nvarchar] (50) NULL , [FechaCaducidadSRI] [datetime] NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[AnticiposProveedores] 9:57:02 ******/ CREATE TABLE [dbo].[AnticiposProveedores] ( [Comprobante] [numeric](10, 0) NOT NULL , [CodigoProveedor] [numeric](10, 0) NOT NULL , [Fecha] [datetime] NULL , [Valor] [decimal](20, 4) NULL , [FormaPago] [numeric](18, 0) NULL , [Estado] [numeric](18, 0) NULL , [Observacion] [varchar] (250) NULL , [SucursalCodigo] [bigint] NOT NULL ) ON [PRIMARY] GO fecha de la secuencia de comandos: 12/08/2012 1

/****** Objeto: tabla [dbo].[Producto] fecha de la secuencia de comandos: 12/08/2012 19:57:02 **** **/ CREATE TABLE [dbo].[Producto] ( [Codigo] [bigint] NOT NULL , [CodigoProducto] [varchar] (50) NOT NULL , [CodigoParametroProducto] [numeric](10, 0) NOT NULL , [NombreProducto] [varchar] (250) NOT NULL , [CostoUnitario] [numeric](24, 4) NOT NULL , [FlagIva] [bit] NOT NULL , [Observacion] [nvarchar] (255) NOT NULL , [SucursalCodigo] [bigint] NOT NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[Sucursales] fecha de la secuencia de comandos: 12/08/2012 19:57:02 ** ****/ CREATE TABLE [dbo].[Sucursales] ( [Codigo] [bigint] NOT NULL , [CodigoSucursal] [nvarchar] (25) NOT NULL , [EmpresaCodigo] [int] NOT NULL , [Ciudad] [numeric](10, 0) NOT NULL , [Direccion] [nvarchar] (250) NOT NULL , [Telefonos] [nvarchar] (25) NOT NULL , [Iva] [smallint] NOT NULL , [SiguienteProducto] [int] NOT NULL , [SiguienteProductoParametro] [int] NOT NULL , [SiguienteProductoHistorico] [int] NOT NULL , [SiguienteRetencion] [int] NOT NULL , [SiguienteDevolucion] [int] NOT NULL , [SiguienteEmpleado] [int] NOT NULL , [SiguienteProveedor] [int] NOT NULL , [SgtAnticipoProveedor] [int] NOT NULL , [AutorizacionRetencion] [varchar] (50) NOT NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[FacturaDeCompra] fecha de la secuencia de comandos: 12/08/2012 19:57: 02 ******/ CREATE TABLE [dbo].[FacturaDeCompra] ( [FacturaDeCompra] [bigint] NOT NULL , [OrdenDeCompra] [bigint] NOT NULL , [Serie] [nvarchar] (15) NULL , [Autorizacion] [nvarchar] (20) NULL , [FechaCaducidadAutorizacion] [datetime] NULL , [TipoDocumento] [int] NULL , [Estado] [numeric](10, 0) NULL , [ProveedorCodigo] [numeric](10, 0) NOT NULL , [SubTotalGrabado] [numeric](24, 4) NULL , [SubTotalExento] [numeric](24, 2) NULL , [GastoCompra] [numeric](24, 4) NULL , [PorcentajeIVA] [numeric](24, 4) NULL , [Iva] [numeric](24, 4) NULL , [ValorFactura] [numeric](24, 4) NULL , [NumeroRetencion] [varchar] (50) NULL , [AutRetencion] [nvarchar] (50) NULL , [CodigoRetFte] [int] NULL , [RetencionFte] [numeric](24, 4) NULL , [PorcentajeRetencionFte] [numeric](24, 4) NULL , [CodigoRetIVA] [int] NULL , [RetencionIVA] [numeric](24, 4) NULL , [PorcentajeRetencionIVA] [numeric](24, 4) NULL ,

Query - /****** Objeto:

base de

Page #7

[SucursalCodigo] [bigint] NOT NULL , [Observacion] [nvarchar] (255) NULL , [CodigoBodega] [int] NOT NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[OrdenCompra] fecha de la secuencia de comandos: 12/08/2012 19:57:02 * *****/ CREATE TABLE [dbo].[OrdenCompra] ( [OrdenDeCompra] [numeric](10, 0) NOT NULL , [ProveedorCodigo] [numeric](10, 0) NOT NULL , [EmpleadoCodigo] [numeric](10, 0) NULL , [SucursalCodigo] [bigint] NOT NULL , [Observacion] [nvarchar] (255) NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[ProductoBodegaStock] :57:02 ******/ CREATE TABLE [dbo].[ProductoBodegaStock] ( [CodigoProducto] [bigint] NOT NULL , [CodigoBodega] [int] NOT NULL , [Stock] [numeric](18, 2) NOT NULL , [SucursalCodigo] [bigint] NOT NULL ) ON [PRIMARY] GO fecha de la secuencia de comandos: 12/08/2012 19

/****** Objeto: tabla [dbo].[Devoluciones] fecha de la secuencia de comandos: 12/08/2012 19:57:02 ******/ CREATE TABLE [dbo].[Devoluciones] ( [Devolucion] [bigint] NOT NULL , [FacturaCompra] [bigint] NULL , [OrdenCompra] [bigint] NULL , [ValorDevolucion] [decimal](24, 4) NULL , [Observacion] [varchar] (255) NULL , [SucursalCodigo] [bigint] NOT NULL , [CodigoBodega] [int] NOT NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[FacturaDeCompraDetalles] 2 19:57:02 ******/ CREATE TABLE [dbo].[FacturaDeCompraDetalles] ( [FacturaDeCompra] [bigint] NULL , [OrdenDeCompra] [bigint] NULL , [Item] [int] NULL , [ProductoCodigo] [bigint] NULL , [CantidadRecibida] [decimal](24, 4) NULL , [CostoUnitario] [decimal](24, 4) NULL , [FlagIva] [bit] NOT NULL , [SucursalCodigo] [bigint] NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[OrdenDeCompraDetalles] 19:57:02 ******/ CREATE TABLE [dbo].[OrdenDeCompraDetalles] ( [OrdenDeCompra] [numeric](10, 0) NOT NULL , [Item] [int] NULL , [ProductoCodigo] [bigint] NULL , [CantidadSolicitada] [decimal](24, 4) NULL , [CostoUnitario] [decimal](24, 4) NULL , [FlagIva] [bit] NOT NULL , [SucursalCodigo] [bigint] NULL ) ON [PRIMARY] GO /****** Objeto: tabla [dbo].[DevolucionesDetalle] :57:03 ******/ CREATE TABLE [dbo].[DevolucionesDetalle] ( [Devolucion] [bigint] NULL , [FacturaCompra] [bigint] NULL , [OrdenCompra] [bigint] NULL , [ProductoCodigo] [bigint] NULL , [Item] [int] NULL , [CantidadDevolucion] [decimal](24, 4) NULL , [CostoUnitario] [numeric](24, 4) NULL , [SucursalCodigo] [bigint] NULL ) ON [PRIMARY] GO fecha de la secuencia de comandos: 12/08/201

fecha de la secuencia de comandos: 12/08/2012

fecha de la secuencia de comandos: 12/08/2012 19

Query - /****** Objeto:

base de

Page #8

ALTER TABLE [dbo].[Bodegas] WITH NOCHECK ADD CONSTRAINT [PK_Bodegas] PRIMARY KEY CLUSTERED ( [Codigo], [SucursalCodigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[Ciudad] WITH NOCHECK ADD CONSTRAINT [PK_Ciudad] PRIMARY KEY CLUSTERED ( [Codigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[Empleado] WITH NOCHECK ADD CONSTRAINT [PK_Empleado] PRIMARY KEY CLUSTERED ( [Codigo], [SucursalCodigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[Empresa] WITH NOCHECK ADD CONSTRAINT [PK_Empresa] PRIMARY KEY CLUSTERED ( [Codigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[Parametro] WITH NOCHECK ADD CONSTRAINT [PK_Parametro] PRIMARY KEY CLUSTERED ( [Codigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[ParametroProducto] WITH NOCHECK ADD CONSTRAINT [PK_ParametroProducto] PRIMARY KEY CLUSTERED ( [CodigoLinea], [SucursalCodigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[ProductoHistorico] WITH NOCHECK ADD CONSTRAINT [PK_ProductoHistorico] PRIMARY KEY CLUSTERED ( [Codigo], [SucursalCodigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[Proveedor] WITH NOCHECK ADD CONSTRAINT [PK_Proveedor] PRIMARY KEY CLUSTERED ( [Codigo], [SucursalCodigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[AnticiposProveedores] WITH NOCHECK ADD CONSTRAINT [PK_AnticiposProveedores] PRIMARY KEY CLUSTERED ( [Comprobante], [CodigoProveedor], [SucursalCodigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[Producto] WITH NOCHECK ADD CONSTRAINT [PK_Producto] PRIMARY KEY CLUSTERED ( [Codigo], [SucursalCodigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[Sucursales] WITH NOCHECK ADD

Query - /****** Objeto:

base de CLUSTERED

Page #9

GO

CONSTRAINT [PK_Sucursales] PRIMARY KEY ( [Codigo] ) ON [PRIMARY]

ALTER TABLE [dbo].[FacturaDeCompra] WITH NOCHECK ADD CONSTRAINT [PK_FacturaDeCompra] PRIMARY KEY CLUSTERED ( [FacturaDeCompra], [OrdenDeCompra], [SucursalCodigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[OrdenCompra] WITH NOCHECK ADD CONSTRAINT [PK_OrdenCompra] PRIMARY KEY CLUSTERED ( [OrdenDeCompra], [SucursalCodigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[ProductoBodegaStock] WITH NOCHECK ADD CONSTRAINT [PK_ProductoBodegaStock] PRIMARY KEY CLUSTERED ( [CodigoProducto], [CodigoBodega], [SucursalCodigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[Devoluciones] WITH NOCHECK ADD CONSTRAINT [PK_Devoluciones] PRIMARY KEY CLUSTERED ( [Devolucion], [SucursalCodigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[ProductoHistorico] WITH NOCHECK ADD CONSTRAINT [IX_ProductoHistorico] UNIQUE NONCLUSTERED ( [Factura], [OrdenCompra], [ProductoCodigo], [SucursalCodigo] ) ON [PRIMARY] GO ALTER TABLE [dbo].[FacturaDeCompra] WITH NOCHECK ADD CONSTRAINT [DF_FacturaDeCompra_TipoDocumento] DEFAULT (0) FOR [TipoDocumento] GO ALTER TABLE [dbo].[AnticiposProveedores] ADD CONSTRAINT [FK_AnticiposProveedores_Proveedor] FOREIGN KEY ( [CodigoProveedor], [SucursalCodigo] ) REFERENCES [dbo].[Proveedor] ( [Codigo], [SucursalCodigo] ) GO ALTER TABLE [dbo].[Producto] ADD CONSTRAINT [FK_Producto_ParametroProducto] FOREIGN KEY ( [CodigoParametroProducto], [SucursalCodigo] ) REFERENCES [dbo].[ParametroProducto] ( [CodigoLinea], [SucursalCodigo] ) GO ALTER TABLE [dbo].[Sucursales] ADD CONSTRAINT [FK_Sucursales_Empresa] FOREIGN KEY ( [EmpresaCodigo]

Query - /****** Objeto:

base de

Page #10

GO

) REFERENCES [dbo].[Empresa] ( [Codigo] )

ALTER TABLE [dbo].[FacturaDeCompra] ADD CONSTRAINT [FK_FacturaDeCompra_Proveedor] FOREIGN KEY ( [ProveedorCodigo], [SucursalCodigo] ) REFERENCES [dbo].[Proveedor] ( [Codigo], [SucursalCodigo] ), CONSTRAINT [FK_FacturaDeCompra_Sucursales] FOREIGN KEY ( [SucursalCodigo] ) REFERENCES [dbo].[Sucursales] ( [Codigo] ) GO ALTER TABLE [dbo].[OrdenCompra] ADD CONSTRAINT [FK_OrdenCompra_Empleado] FOREIGN KEY ( [EmpleadoCodigo], [SucursalCodigo] ) REFERENCES [dbo].[Empleado] ( [Codigo], [SucursalCodigo] ), CONSTRAINT [FK_OrdenCompra_Proveedor] FOREIGN KEY ( [ProveedorCodigo], [SucursalCodigo] ) REFERENCES [dbo].[Proveedor] ( [Codigo], [SucursalCodigo] ), CONSTRAINT [FK_OrdenCompra_Sucursales] FOREIGN KEY ( [SucursalCodigo] ) REFERENCES [dbo].[Sucursales] ( [Codigo] ) GO ALTER TABLE [dbo].[ProductoBodegaStock] ADD CONSTRAINT [FK_ProductoBodegaStock_Bodegas] FOREIGN KEY ( [CodigoBodega], [SucursalCodigo] ) REFERENCES [dbo].[Bodegas] ( [Codigo], [SucursalCodigo] ), CONSTRAINT [FK_ProductoBodegaStock_Producto] FOREIGN KEY ( [CodigoProducto], [SucursalCodigo] ) REFERENCES [dbo].[Producto] ( [Codigo], [SucursalCodigo] ) GO ALTER TABLE [dbo].[Devoluciones] ADD CONSTRAINT [FK_Devoluciones_FacturaDeCompra] FOREIGN KEY ( [FacturaCompra], [OrdenCompra], [SucursalCodigo] ) REFERENCES [dbo].[FacturaDeCompra] ( [FacturaDeCompra], [OrdenDeCompra], [SucursalCodigo] ) GO ALTER TABLE [dbo].[FacturaDeCompraDetalles] ADD

Query - /****** Objeto:

base de

Page #11

GO

CONSTRAINT [FK_FacturaDeCompraDetalles_FacturaDeCompra] FOREIGN KEY ( [FacturaDeCompra], [OrdenDeCompra], [SucursalCodigo] ) REFERENCES [dbo].[FacturaDeCompra] ( [FacturaDeCompra], [OrdenDeCompra], [SucursalCodigo] ), CONSTRAINT [FK_FacturaDeCompraDetalles_Producto] FOREIGN KEY ( [ProductoCodigo], [SucursalCodigo] ) REFERENCES [dbo].[Producto] ( [Codigo], [SucursalCodigo] ), CONSTRAINT [FK_FacturaDeCompraDetalles_ProductoHistorico] FOREIGN KEY ( [FacturaDeCompra], [OrdenDeCompra], [ProductoCodigo], [SucursalCodigo] ) REFERENCES [dbo].[ProductoHistorico] ( [Factura], [OrdenCompra], [ProductoCodigo], [SucursalCodigo] )

ALTER TABLE [dbo].[OrdenDeCompraDetalles] ADD CONSTRAINT [FK_OrdenDeCompraDetalles_OrdenCompra] FOREIGN KEY ( [OrdenDeCompra], [SucursalCodigo] ) REFERENCES [dbo].[OrdenCompra] ( [OrdenDeCompra], [SucursalCodigo] ), CONSTRAINT [FK_OrdenDeCompraDetalles_Producto] FOREIGN KEY ( [ProductoCodigo], [SucursalCodigo] ) REFERENCES [dbo].[Producto] ( [Codigo], [SucursalCodigo] ) GO ALTER TABLE [dbo].[DevolucionesDetalle] ADD CONSTRAINT [FK_DevolucionesDetalle_Devoluciones] FOREIGN KEY ( [Devolucion], [SucursalCodigo] ) REFERENCES [dbo].[Devoluciones] ( [Devolucion], [SucursalCodigo] ), CONSTRAINT [FK_DevolucionesDetalle_Producto] FOREIGN KEY ( [ProductoCodigo], [SucursalCodigo] ) REFERENCES [dbo].[Producto] ( [Codigo], [SucursalCodigo] ), CONSTRAINT [FK_DevolucionesDetalle_ProductoHistorico1] FOREIGN KEY ( [FacturaCompra], [OrdenCompra], [ProductoCodigo], [SucursalCodigo] ) REFERENCES [dbo].[ProductoHistorico] ( [Factura], [OrdenCompra], [ProductoCodigo], [SucursalCodigo] )

Query - /****** Objeto: GO

base de

Page #12