
/*------ ATD 358071 ------*/

IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'ITNFSAICOMPLEMENTO' and column_name = 'DATAATUALIZACAOCUSTO')
	ALTER TABLE ITNFSAICOMPLEMENTO ADD DataAtualizacaoCusto DATETIME NULL
GO

IF not EXISTS (SELECT 1 FROM ITEM WHERE OID = 39114) 
insert into item (rescopo, criadopor, atualizadopor, codigo, criadoem, atualizadoem , observacao, nome, cid, oid, excluido) 
values (7, 1, 1, '18', '01/01/01', '01/01/01', '','Casa e Tinta', 18, 39114, 0) 
go

IF not EXISTS (SELECT 1 FROM CATEGORIA WHERE OID = 39114) 
insert into categoria (rsuper, nomeinterno, oid) 
values (38473, 'VERSAO_SISTEMA_CASAETINTA', 39114) 
go

IF NOT EXISTS(SELECT 1 
				FROM SYSINDEXES SI
				 JOIN SYSINDEXKEYS SIK ON SIK.INDID = SI.INDID
				 JOIN SYSOBJECTS T ON T.ID = SIK.ID AND T.ID = SI.ID
				 JOIN SYSCOLUMNS SC ON SC.ID = T.ID AND SC.COLID = SIK.COLID
				WHERE T.NAME = 'NOTA_ELETRONICA_XML'
				AND SC.NAME = 'NUMORD'
				AND SIK.KEYNO > 0 ) -- tem que colocar KEYNO senao pode aparecer colunas indesejadas
CREATE INDEX NOTA_ELETRONICA_XML_IDX1 ON NOTA_ELETRONICA_XML(NUMORD)
GO
