Database LibreOffice - Primary Key
LibreOffice Primary Key
Database creation using the graphical user interface (GUI) is explained step by step, using the Media table as an example.
Launch the table editor by clicking on Create Table in Design View.
ID field:
In the first column, enter the Field Name ID. Then type the Tab key to move to the Field Type column. Alternatively, click with the mouse on the next column to select it, or press the Enter key.
Select Integer [INTEGER] from the list as the field type. The default is Text [VARCHAR]. Integers can store a number with up to 10 digits. In addition, Integer is the only type available in the GUI that can be given an automatically incrementing value.
Tip
To rapidly make a selection from the Field Type list using the keyboard, type the key corresponding to the first letter of your choice. Repeated typing of this key can be used to change the selection. For example, typing D can change your selection from Date to Date/Time or to Decimal.
Set ID as the primary key by clicking the rectangle in front of its field name with the right mouse button and selecting Primary Key from the context menu. A key symbol appears before ID.
Note
The primary key serves one purpose only – to uniquely identify the record. Therefore you can use an arbitrary name for this field. In the example, we have used the commonly used name ID (identification).
Under Field properties for the ID field, change AutoValue from No to Yes. This causes the primary key to be automatically incremented. In the internal database, the count begins at 0.
AutoValue can be set for only one field in a table. Choosing AutoValue > Yes automatically sets this field to be the primary key if a primary key has not been set already.