1

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?

MDCCL
  • 8,530
  • 3
  • 32
  • 63
Poldi60
  • 11
  • 1

2 Answers2

0

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.

Joe W
  • 1,058
  • 9
  • 20
0

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)
);
CL.
  • 5,325
  • 1
  • 22
  • 23