
/*------ ATD 415321 ------*/
-- Criacao da tabela SPED_H020_MEMORIA
IF NOT EXISTS (SELECT 1 FROM SYSOBJECTS WHERE xtype='U' AND name='SPED_H020_MEMORIA') 
BEGIN
   CREATE TABLE SPED_H020_MEMORIA(
   ID INT IDENTITY NOT NULL,
   FILIAL CHAR(2),
   MES SMALLINT, 
   ANO SMALLINT, 
   CODPRO CHAR(5), 
   NUMORD INT, 
   ITEM CHAR(5),
   QTDEUTILIZADA NUMERIC(15,5),
   BASEICMSMEDIO NUMERIC(15,5),
   BASESTMEDIA NUMERIC(15,5),
   ICMSOPMEDIO NUMERIC(15,5),
   CREDITOICMSMEDIO NUMERIC(15,5),
   DATA DATETIME,
   BASEICMS NUMERIC(15,5),
   BASEST NUMERIC(15,5),
   ICMSOP NUMERIC(15,5),
   CREDITOICMS NUMERIC(15,5),
   ICMSOP2 NUMERIC(15,5))

   ALTER TABLE SPED_H020_MEMORIA ADD CONSTRAINT PK_SPED_H020_MEMORIA PRIMARY KEY CLUSTERED(ID)
END
GO

-- Criacao da tabela SPED_INVENTARIO_H020
IF NOT EXISTS (SELECT 1 FROM SYSOBJECTS WHERE xtype='U' AND name='SPED_INVENTARIO_H020') 
BEGIN
   CREATE TABLE SPED_INVENTARIO_H020(
   ID INT IDENTITY NOT NULL,
   FILIAL CHAR(2),
   MES SMALLINT,
   ANO SMALLINT, 
   CODPRO CHAR(5), 
   SALDOCUST NUMERIC(15,5), 
   BASEICMSMEDIO NUMERIC(15,5), 
   BASESTMEDIA NUMERIC(15,5), 
   ICMSOPMEDIO NUMERIC(15,5),
   CREDITOICMSMEDIO NUMERIC(15,5),
   DATA DATETIME)

   ALTER TABLE SPED_INVENTARIO_H020 ADD CONSTRAINT PK_SPED_INVENTARIO_H020 PRIMARY KEY CLUSTERED(ID)
END
GO
