Easy way to define new attributes to entity after initial schema definition


In SQL, we can “ALTER TABLE my_table ADD new_column varchar;” to add a new column to an existing table. Can we do the similar in TypeDB? After initially defining the schema, I realised I wanted to define a new attribute to an entity type. I chekced the documentation and there was no obvious solution. There is ‘define’ and ‘undefine’, wondering if there can be an ‘alter’ as well.

Thanks in advance.

Hi Alan,

You can use define again to add more attributes to an entity type. Here’s an example:

We initially define a person with a first name.

    first-name sub attribute, value string;
    person sub entity, owns first-name;

Following this, we might decide we also want to people to have last names as well.

    last-name sub attribute, value string;
    person sub entity, owns last-name;

Now, our person entity has both a first-name and a last-name.

I agree with you that the documentation surrounding the semantics of using define like this could use improvement. I’ve filed an issue with our docs to ensure that this gets addressed.

1 Like