I am facing the following problem:

I have a table with customer information like the customer number, i.e. customerID set up as the primary key, and, besides a number of other data, also a country value in the form of a country code, countryID.

However, customer data from other countries should also be imported into this table. Although the customer numbers are unique within a country, they are not cross-country. Customer numbers should not be changed for organizational reasons.

How can a key still be ensured for each customer in this table?


I would use countryID, CustomerID as your unique key as you have stated that you will have a unique customer id for each country. I would start with countryID as that will be unique in the system and you can add in customerID in order to get a unique key for each customer.

  • Thank you very much, that would have been about my idea, too. Since I'm not very familiar with sql, I don't really know how to implement it. Can someone please outline what statements I need in SQLite? –  Poldi60 Jan 29 '19 at 20:51

It is possible to have a primary key consisting of multiple columns. This requires writing the constraint separately, as a table constraint:

CREATE TABLE customers (
    countryID   INTEGER,
    customerID  INTEGER,
    PRIMARY KEY (countryID, customerID)

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.