Support > Repository > Primary key option > Branch number by compound key
ja | en

You can prepare the branch number as part of the composite key.


An example of preparing "customer ID" and "branch number" is shown in Fig.(Each is the primary key.The initial value of the branch number is 1.

Figure 1 Example of preparing customer ID and branch number

Here, using the copy registration function,With the same customer IDI will try to register.

The primary key "customer ID" is input,Same customer IDThe branch number is given when inputting the branch number is realized.

On the registration/update screen, the branch number is automatically hidden.

Figure 2 Register data with the same customer ID

The branch number increases.(Figure 3)

Figure 3 The branch number has become 2

The branch number is managed for each data.If the customer ID changes, the branch number will be 1.

Figure 4 Example of different customer ID

Definition method

Figure 5 shows an example of "customer ID" and "branch number" items prepared for customer model.

Figure 5 Customer model

The customer ID is the primary key.In this example it is a character string, so we can enter it.(We do not use "order" for automatic number assignment.)

Figure 6 Customer ID definition (without order)

The branch number is also the primary key.And "Use as branch number" is enabled.The starting number is 1.

Figure 7 Definition of branch number
This branch number designation does not function unless "use as primary key" is valid.
(A model that uses a branch number is always a compound key.)


Using an order for the primary key (automatic numbering), but when used in conjunction with setting that does not use the sequence at the time of copy registration, it is said that "only at the time of copy registration (because duplication of primary key occurs)" branch number is given I will explain an example.

It is a new registration screen."Customer ID" and "branch number" are both hidden.

Figure 8 New registration screen (using sequence)

It is the screen immediately after new registration.The branch number is "1".

Figure 9 Details screen immediately after new registration

I will try copy registration next.In copy registration, the order is not used, so "customer ID" will be duplicated.

Fig. 10 Copy registration

The branch number increases.

Figure 11 Detailed screen immediately after copy registration

Definition method

The customer ID uses the order, but at the same time, the setting "Do not use the order at copy registration" is enabled.(FIG. 12)

Figure 12 Customer ID definition (using order)

The definition of the branch number is the same as in Figure 7.The branch number designation is valid for "Use as primary key".

Figure 13 Definition of branch number

Example of execution

Here is an example of setting alphabetical notation A, B, C, ... instead of integer numbers 1, 2, 3, .... Figure 14 is just after registering the data for the primary key "A-0001".The branch number is not included here.

Figure 14 Registering data for primary key "A-0001"

Using the copy registration function, try to re-register the data with the same primary key.(FIG. 15)

Figure 15 Re-register data with the same primary key "A-0001"

"A" was added to the end of the key.This is a branch number.

Figure 16 The branch number "A" was assigned

If you register with the same primary key "A - 0001" again, the branch number "B" will be granted this time. Subsequently, the branch number is assigned A, B, C, ... Z, and after Z, it is AA.

Figure 17 The branch number "B" was assigned

Definition method

We prepare three items "customer ID" "branch number (hidden)" "customer ID".The first "customer ID" is displayed in the registration/update screen.Another "customer ID" is for display, and it displays it in a form joined with the branch number at the end according to the calculation formula.

Figure 18 Model definition

Detailed setting of each item is as follows.

item name Item ID Type Primary key Branch number order Start number DB storage Hidden on input Hidden on output
Customer ID customerid String - - - -
Branch number (hidden) branchid Numerical value - 1
Customer ID customeridshow String - - - - - -

The following automatic calculation formula is applied to the "customer ID" (customeridshow) item used for display.


hereFunction A1FORMATReturns alphabets that conform to Excel's column naming convention.

Figure 19 Setting expression at display

Wagby may not be able to use compound key models with some functions.
To avoid this constraint,Branch number applying narrow-down function with single keyYou can also set.