IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'TBL_ICMS_AJUSTES' and xtype = 'U') 
BEGIN 
CREATE TABLE TBL_ICMS_AJUSTES(
	[CD_CTR] [int] NOT NULL,
	[UF] [char](2) NOT NULL,
	[COD_AJUSTE] [varchar](50) NOT NULL,
	[DS_AJUSTE] [varchar](250) NULL,
	[TIPO] [int]  NULL,
	[DISPOSITIVO_LEGAL] [varchar](100) NULL,
	[DATA_INICIO] [datetime] NULL,
	[DATA_FIM] [datetime] NULL,
	[DT_CAD] [datetime] NULL,
	[CD_USU] [int] NULL,
 CONSTRAINT [PK_TBL_ICMS_AJUSTES] PRIMARY KEY CLUSTERED ([CD_CTR] ASC)
) 
end

IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'TBL_ICMS_AJUSTES_OBS' and xtype = 'U') 
BEGIN 
    CREATE TABLE TBL_ICMS_AJUSTES_OBS(
        CD_CTR int NOT NULL,
        CD_OBS int NOT NULL,
        DS_OBS varchar(250) NULL,
        REGISTRO varchar(4) NULL,
        VINC_CUPOM int NULL,
        DIFAL int NULL,
        DARE int NULL,
        DIFAL_ATIVO_PERMANENTE int NULL,
        DIFAL_USO_CONSUMO int NULL,
        ICMS_EMIT_SIMPLES int NULL,
        DT_CAD datetime NULL,
        CD_USU int NULL,
        CONSTRAINT PK_TBL_ICMS_AJUSTES_OBS PRIMARY KEY CLUSTERED (CD_CTR ASC, CD_OBS ASC),
        CONSTRAINT FK_TBL_ICMS_AJUSTES_OBS FOREIGN KEY (CD_CTR)  REFERENCES TBL_ICMS_AJUSTES (CD_CTR) 
          
    )
END
