Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 709 Bytes

key-constraints.md

File metadata and controls

34 lines (24 loc) · 709 Bytes

Working with key contraints

Setting Primary Key

Single Key

Schema schema = new Schema();

Field idField = new IntegerField("id");
schema.addField(idField);

Field nameField = new StringField("name");
schema.addField(nameField);

schema.setPrimaryKey("id");
String primaryKey = schema.getPrimaryKey();

Composite Key

Schema schema = new Schema();

Field idField = new IntegerField("id");
schema.addField(idField);

Field nameField = new StringField("name");
schema.addField(nameField);

Field surnameField = new StringField("surname");
schema.addField(surnameField);

schema.setPrimaryKey(new String[]{"name", "surname"});
String[] compositeKey = schema.getPrimaryKey();