1 Table
It allows defining the structure of a table to be created in the database. The root element is table which, in turn, can contain the following elements:
- column: allows defining the columns that make up the table.
- primary: allows defining the primary key of the table.
- unique: allows defining uniqueness restrictions of the table.
- index: allows defining indexes on the table.
- foreign: allows defining the foreign keys of the table.
- check: allows defining control restrictions on the table columns.
Information
It is important to respect the order of the elements specified above, otherwise the XML to SQL code transformer returns an error message or produces unwanted statements.
It allows generating a table on database.
<table
name='name'
temp='y|yes|n|no'
log='y|yes|n|no'
type='type'
under='under'
onexception='ignore'
>
<column /> *
<primary /> ?
<unique /> *
<index /> *
<foreign /> *
<check /> *
</table>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Table name. | |||
Atemp | string | n|no | If the table is temporary, the value must be assigned y or yes . | ||
Alog | string | n|no | It applies if it has been indicated that the table is temporary. By default temporary tables are created WITH NO LOG (non transactional). If you require transactions, you must assign this attribute the value y or yes . | ||
Atype | string | In case the table is type table, the name of the row data type is indicated. | |||
Aunder | string | If you want to create a subtype, this attribute indicates the parent table from which it inherits its properties. | |||
Aonexception | string | The ignore value is informed only to to control that in the event that an error occurs, the system continues with the rest of the statements. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Ecolumn | Columns that make up the table See section column. | ||||
Eprimary | Primary key of the table. See section primary. | ||||
Eunique | The uniques constraints to create on table. See section unique. | ||||
Eindex | Indexes to create on table. See section index. | ||||
Eforeign | Foreign keys of table. See section foreign. | ||||
Echeck | The checks constraints to create on table. See section check. |
Taking into account the attributes of the table, there are two ways to create a table.
Without the attribute type: to create the structure of this table the tag column will be used indicating the column name and type.
<table name='gcliente'> <column name='codigo' type='integer' /> <column name='varlog' type='char' size='4' /> </table>
With the type attribute: the temporary table will be created without the need to define the columns that will build up it. To do this, a structure already created on a type object will be used.
<table name='t_extend' type='r_main'> <primary name='pk_t_main' columns='codigo' /> </table>
If you want to create a table with the structure of a type element and some other column, you simply have to add the tag 'column'.
<table name='t_extend' type='r_main'> <column name='desc' type='char' size='40' /> <primary name='pk_t_main' columns='codigo' /> </table>
1.1 Column
It allows defining the columns that make up a table.
<column
name='name'
type='type'
size='size'
type_like='type_like'
default='default'
required='required'
/>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Column name | |||
Atype | string | Data type of the column. The supported values are: rowid, serial, serialref, smallint, int, int8, integer, smallfloat, float, decimal, boolean, char, nchar, varchar, lvarchar, nvarchar, date, datetime, interval, byte, text, clob, blob, geometry . | |||
Asize | string | Data type size. It applies according to the type reported in the attribute type. | |||
Atype_like | string | It allows indicating a column of another table from which to obtain the type and size. It does not inherit the rest of properties or constraints. | |||
Adefault | string | Column default value. They can be constants or literals already predefined in the database. Ej.: user, today, current. | |||
Arequired | string | n|no | Indicate if the column will allow nulls. With value y or yes the column is declared NOT NULL. |
Taking into account the attributes of the table, there are two ways to create a table.
Without the attribute type: to create the structure of this table the tag column will be used indicating column name and type.
<column name='gid' type='serial' required='yes' /> <column name='cat' type='integer' /> <column name='asother' type_like='table.column' required='yes' /> <column name='fips_cntry' type='varchar' size='80' /> <column name='cntry_name' type='varchar' size='80' /> <column name='area' type='decimal' size='14,2' /> <column name='pop_cntry' type='decimal' size='14,2' />
1.2 Primary
This element must be defined within the table element, and allows indicating the primary key of table.
<primary
name='name'
columns='columns'
table='table'
/>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Name of the primary key. | |||
Acolumns | string | The columns that make up the primary key separated by a comma. | |||
Atable | string | The name of the table, which by default is the table where the element is included. |
<primary name='p_cbancpro' columns='empcode,ctafin' />
1.3 Unique
This element is defined within the table element, and is used to create a restriction of type unique constraint.
<unique
name='name'
columns='columns'
oracle='oracle'
/>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Alternative Key Name. | |||
Acolumns | string | Columns that make up the alternative key, separated by a comma. | |||
Aoracle | string | In Oracle, creation for special cases can be ignored, indicating the value no , for example in temporary tables. |
<unique name='u_cbancpro2' columns='ctafin,empcode' />
1.4 Anchor
This element must be defined within the 'table' element, and allows you to specify the table indexes.
<index
name='name'
columns='columns'
oracle='oracle'
/>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Index Name. | |||
Acolumns | string | Columns that make up the index, separated by a comma. | |||
Aoracle | string | In Oracle, creation for special cases can be ignored, indicating the value no , for example in temporary tables. |
<index name='i_wic_jrep_box_celldata1' columns='rep_code, box_row, box_col, box_when' unique='y' oracle='no' />
1.5 Foreign
This element must be defined within the 'table' element, and allows indicating the foreign keys of table.
<foreign
name='name'
columns='columns'
references='references'
refcols='refcols'
table='table'
unique='y|yes'
ondeletecascade='y|yes'
conditional='y|yes'
/>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Foreign Key Name. | |||
Acolumns | string | Columns that make up the foreign key, separated by a comma. | |||
Areferences | string | It is used to indicate the table to which the foreign key refers. | |||
Arefcols | string | It shows the columns to which it refers. | |||
Atable | string | Name of the source table, which by default is the table where the foreign element is defined. | |||
Aunique | string | Indicates that the index associated with the foreign key is unique. | |||
Aondeletecascade | string | Indicates if deletion will be in cascade. | |||
Aconditional | string | Indicates if it is conditional. Its creation is conditioned to the existence of the referenced table. |
<foreign name='f_wic_change_logrcs1' columns='chg_seqno' references='wic_change_log' refcols='chg_seqno' conditional='y' />
1.6 Check
This tag must be inside a 'table' tag, and it is used to specify the validation checks that the table will use.
<check
name='name'
engine='engine'
>
<constraint /> *
</check>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Name of the control restriction. | |||
Aengine | string | It is used to specify the database management system (DBMS), since it is possible that for the different DBMS its syntax is different. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Econstraint | This tag must be within the check tag. Inside it contains the code to perform the validations. The code entered must be introduced on a CDATA for the transformer to interpret it as written. |
<check name='c_gartdele1'> <constraint> codpot IN ('P', 'C', '0') </constraint> </check>
<check name='c_gartdele2'> <constraint> fecini <= fecfin </constraint> </check>