0

I have created a database with one table like this:

How to create a primary key like: (Patient, Date, Test, Parameter) ?

The database will be holding data for numerous patients examined multiple times on different dates and for each examination multiple tests will be done resulting in multiple parameters and its values plus additional data.

The combination of (Patient, Date, Test, Parameter) will be unique however.

  • What is your database setup - Firebird Embedded, HSQLDB Embedded, or an external setup such as PostgreSQL? – Jim K Oct 10 at 14:56
0

All columns that will be used for the primary key are required to be NOT NULL. To set this, edit the table and for each column, set Entry Required to Yes in the lower area of the editor.

Then go to Tools -> SQL and run the following command.

ALTER TABLE "BloodTestResults" ADD PRIMARY KEY ("Patient", "Date", "Test", "Parameter");

Save, close and reopen the .odb file. Now the primary key should be in effect.

key icon next to 4 columns

Attempting to add duplicates will produce an error.

error adding duplicate

This was tested with a Firebird Embedded database setup.

Reference: SQL - Primary Key

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.