
/*------ ATD 272183 ------*/
-- Adicionando coluna NUMORDNFENTRA na tabela REFERENCIANFCOMPLEMENTAR
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'REFERENCIANFCOMPLEMENTAR' AND COLUMN_NAME = 'NUMORDNFENTRA') 
alter TABLE dbo.REFERENCIANFCOMPLEMENTAR add NUMORDNFENTRA INT NULL
go
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DADOSNOTANFE' AND COLUMN_NAME = 'idDest') 
	ALTER TABLE DBO.DADOSNOTANFE ADD idDest SMALLINT DEFAULT 1
go
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DADOSNOTANFE' AND COLUMN_NAME = 'IndFinal') 
	ALTER TABLE DBO.DADOSNOTANFE ADD IndFinal SMALLINT  DEFAULT 0
go
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DADOSNOTANFE' AND COLUMN_NAME = 'IndPres') 
	ALTER TABLE DBO.DADOSNOTANFE ADD IndPres SMALLINT  DEFAULT 1
go
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DADOSNOTANFE' AND COLUMN_NAME = 'IdEstrangeiro') 
	ALTER TABLE DBO.DADOSNOTANFE ADD IdEstrangeiro CHAR(20) DEFAULT ''
go	
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DADOSNOTANFE' AND COLUMN_NAME = 'IndIeDest') 
	ALTER TABLE DBO.DADOSNOTANFE ADD IndIeDest SMALLINT 
go
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'COMPLEMENTONFSAIDA_I' AND type = 'TR')
   drop trigger COMPLEMENTONFSAIDA_I
go

CREATE TRIGGER COMPLEMENTONFSAIDA_I ON COMPLEMENTONFSAIDA FOR INSERT AS
BEGIN
    UPDATE COMPLEMENTONFSAIDA SET DTEMIS = GETDATE() WHERE NUMORD = (SELECT NUMORD FROM INSERTED)
    RETURN
END
GO

IF not EXISTS (SELECT 1 FROM DADOADICIONAL WHERE OID = 37387) insert into dadoadicional ( RCLASSECONCRETA,RAPLICATIVO,RDOMINIO,RLISTA,RTIPO,RITEM,RESTRICAO,VISIVEL,MASCARA,PADRAO,MAXIMO,MINIMO,VALOR,OID) values (7,7    ,7,7,1013,44,0,0,'','',1,0,'Identificador estrangeiro',37387)
go
