This document provides a summary of the domain-specific language recognized by dbdia to define relational schemas and ER models (you may also have a look at the actual ANTLR grammar in use).
C-style comments can be used.
... // single-line comment
/*
multi-line
comment
*/
ID:
[Alpha] ((Alpha|Digit|\_)*(Alpha|Digit))?
Notes:
- You can use Unicode letters with accents.
- The underscore can not be used as a beggining or end character (versions 0.4 or higher).
dbdia performs a few semantic checks:
- You can not define the same symbol twice at the same level of scoping. An error is issued if you try to define two entities/relationships with the same name in an ER model, and similary for tables in relational schemas, fields in tables or entities, etc.
- You can not make a reference to an undefined symbol. Forward references are allowed though.
relationalSchema:
tableDefinition*
tableDefinition:
'table' name_of_table=ID '(' tableField (',' tableField)* ')'
tableField:
(primaryKeyFieldDef | optionalFieldDef | plainFieldDef)
type_identifier=ID? // optional identifier for field type
('-->' table=ID '.' field=ID)? // optional foreign key reference
primaryKeyFieldDef:
'_' name=ID '_'
optionalFieldDef: // for optional (i.e. nullable) fields
name=ID '?'
plainFieldDef:
name=ID
entRelModel:
entRelModelItem*
entRelModelItem:
entity // Entity type
| relationship // Relationship
| weakEntity // Weak entity type
entity:
name=ID '(' fields=(entityField (',' entityField)*)? ')'
entityField :
keyField
| nonKeyField
nonKeyField:
simpleField
| optionalField
| derivedField
| compositeField
| multivalueField
keyField:
'_' name=ID '_'
simpleField:
name=ID
optionalField:
name=ID '?'
derivedField:
'.' name=ID '.'
compositeField :
name=ID '(' subfields=(nonKeyField (',' nonKeyField )*) ')'
multivalueField:
'{' (simpleField | compositeField) '}'
relation:
entityA=ID
constrA=relationshipConstraints
'<' name=ID ('(' nonKeyField (',' nonKeyField)* ')')? '>'
constrB=relationConstraints
entityB=ID
relationshipConstraints:
'-'+ ('1' | 'M' | 'N') '-'+ // '-' indicates partial participation
| '='+ ('1' | 'M' | 'N') '='+ // '=' indicates total participation
weakEntity:
name_of_identifying_entity=ID
('-'+ | '='+) // parcial or total participation by identifying entity
'<<' name_of_identifying_relationship=ID '>>'
weak_entity=entity // the actual weak entity type (defined like an entity type)