DDL XML

DDL XML

<table name='galmacen'>
   <!-- COLUMNS -->
   <column name='almid'  type='serial' required='y' />
   <column name='codigo' type='char'  size='6' required='y' />
   <column name='nomalm' type='varchar' size='40' required='y' />
   <column name='tercer' type='char'  size='12' required='y' />
   <column name='tipdir' type='char'  size='6' default='0' required='y' />
   <column name='empcode' type='char' size='4' required='y' />
   <column name='agrupa' type='char'  size='4' required='y' />
   <column name='recint' type='char'  size='6' required='y' />
   <column name='delega' type='char'  size='6' />
   <column name='depart' type='char'  size='6' />
   <column name='codpre' type='char'  size='10' /><!-- Partida presupuestaria. el almacen se ha creado para suministrar un proyecto -->
   <column name='stkneg' type='smallint' default='0' required='y' />
   <column name='stkrup' type='char' size='1' default='N' required='y' />
   <column name='tipval' type='char' size='1' required='y' />
   <column name='cosuni' type='char' size='1' default='N' required='y' />
   <column name='costol' type='smallint' default='0' required='y' />
   <column name='fecval' type='date' required='y' />
   <column name='aplven' type='smallint' default='0' required='y' />
   <column name='indlot' type='smallint' default='1' required='y' />
   <column name='disdel' type='smallint' default='0' required='y' />
   <column name='reflec' type='int' />
   <column name='capdes' type='decimal' size='11,3' default='0.000' required='y' />
   <column name='horini' type='smallint' default='0' required='y' />
   <column name='horfin' type='smallint' default='0' required='y' />
   <column name='tippro' type='char' size='4' />
   <column name='impre1' type='char' size='10' />
   <column name='impre2' type='char' size='10' />
   <column name='tipast' type='char' size='4' />
   <column name='fecalt' type='date' default='today' required='y' />
   <column name='fecbaj' type='date' />
   <column name='fecult' type='date' required='y' />
   <column name='feccon' type='date' />
   <column name='inipot' type='smallint' />
   <column name='estado' type='char' size='1' required='y' />
   <column name='errnum' type='smallint' default='0' required='y' />
   <column name='wkfnum' type='smallint' />
   <column name='auxchr1' type='char' size='1' />
   <column name='auxchr2' type='char' size='1' />
   <column name='auxchr3' type='char' size='1' />
   <column name='auxchr4' type='char' size='1' />
   <column name='auxchr5' type='char' size='1' />
   <column name='auxfec1' type='date' />
   <column name='auxfec2' type='date' />
   <column name='auxnum1' type='smallint' />
   <column name='auxnum2' type='smallint' />
   <column name='auxnum3' type='smallint' />
   <column name='user_created' type='char' size='20' default='user' required='y' />
   <column name='date_created' type='datetime' size='year to second' default='current' required='y' />
   <column name='user_updated' type='char' size='20' default='user' required='y' />
   <column name='date_updated' type='datetime' size='year to second' default='current' required='y' />


   <!-- INDEXES -->
   <!-- f_galmacen1 == foreign key -->
   <!-- f_galmacen2 == foreign key -->
   <!-- f_galmacen3 == foreign key -->
   <!-- f_galmacen4 == foreign key -->
   <!-- f_galmacen5 == foreign key -->
   <!-- f_galmacen6 == foreign key -->
   <!-- f_galmacen7 == foreign key -->

   <primary name='p_galmacen' columns='codigo' />

   <unique name='u_galmacen1' columns='almid' />

   <!-- FOREIGN KEYS -->
   <foreign name='f_galmacen1' columns='tercer'  references='ctercero' refcols='codigo' />
   <foreign name='f_galmacen2' columns='tipast'  references='gconasih' refcols='codigo' />
   <foreign name='f_galmacen3' columns='agrupa'  references='gagrupac' refcols='codigo' />
   <foreign name='f_galmacen4' columns='delega,depart' references='gdeparta' refcols='delega,depart' />
   <foreign name='f_galmacen5' unique='yes' columns='tercer,tipdir' references='cterdire' refcols='codigo,tipdir' />
   <foreign name='f_galmacen6' columns='recint'  references='galmreci' refcols='codigo' />
   <foreign name='f_galmacen7' columns='empcode' references='cempresa' refcols='empcode' />
   <foreign name='f_galmacen8' columns='tippro'  references='gmovprod' refcols='codigo' />



   <!-- CHECKS -->
   <check name='c_galmacen1'>
    <constraint><![CDATA[
    (tipval IN ('F', 'L', 'M', 'N'))
]]> </constraint>
   </check>

   <check name='c_galmacen2'>
    <constraint><![CDATA[
    (cosuni IN ('S', 'N'))
]]> </constraint>
   </check>

   <check name='c_galmacen3'>
    <constraint><![CDATA[
    (feccon IS NULL OR feccon <= fecval)
]]> </constraint>
   </check>

   <check name='c_galmacen4'>
    <constraint><![CDATA[
    (feccon IS NULL OR
    (feccon IS NOT NULL AND tipast IS NOT NULL))
]]> </constraint>
   </check>

   <check name='c_galmacen5'>
    <constraint><![CDATA[
    (fecbaj IS NULL OR fecalt <= fecbaj)
]]> </constraint>
   </check>

   <check name='c_galmacen6'>
    <constraint><![CDATA[
    (horini <= horfin)
]]> </constraint>
   </check>

   <check name='c_galmacen7'>
    <constraint><![CDATA[
    ((horini BETWEEN 0 AND 23) AND (horfin BETWEEN 0 AND 23))
]]> </constraint>
   </check>

   <check name='c_galmacen8'>
    <constraint><![CDATA[
    (costol = 0 OR (costol > 0 AND tipval = 'M'))
]]> </constraint>
   </check>

   <check name='c_galmacen9'>
    <constraint><![CDATA[
    errnum = 0 OR (errnum != 0 AND estado = 'B')
]]> </constraint>
   </check>

   <check name='c_galmacen10'>
    <constraint><![CDATA[
    wkfnum IS NULL OR (wkfnum IS NOT NULL AND errnum != 0)
]]> </constraint>
   </check>

   <check name='c_galmacen11'>
    <constraint><![CDATA[
      stkrup IN ('N', 'G', 'Z')
]]> </constraint>
   </check>

</table>