Subject Re: [firebird-support] Primary key composed by multiple integer fields
Author Mark Rotteveel
On 11-11-2017 11:13, m_brahim11@... [firebird-support] wrote:
> I need to know please if it is allowed that a primary key has multiple
> integer fields ? and only that. For example a PK that has seven integer
> fields will it decrease the performance table ? I am using FB 3. Thanks

Of course you can do that. See
https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-ddl-tbl.html

<tconstraint> ::=
[CONSTRAINT constr_name]
{ PRIMARY KEY (col_list) [<using_index>]
| UNIQUE (col_list) [<using_index>]
| FOREIGN KEY (col_list)
REFERENCES other_table [(col_list)] [<using_index>]
[ON DELETE {NO ACTION | CASCADE | SET DEFAULT | SET NULL}]
[ON UPDATE {NO ACTION | CASCADE | SET DEFAULT | SET NULL}]
| CHECK (<check_condition>) }"

<col_list> ::= colname [, colname ...]

In other words, a table constraint, including a primary key, can consist
of multiple columns (contrary to a column constraint, which is only on a
single column).

Will it decrease performance? Of course it will, more columns means a
larger key, which means bigger indexes, and thus a decrease in
performance on insert and likely also on lookup. A key of seven integers
means a key of 7 * 4 bytes = 28 bytes (+ maybe some bytes overhead, I
keep forgetting implementation details like that). The decrease in
performance is probably not excessive, but if the decrease in
performance is acceptable or not is up to you.

Mark
--
Mark Rotteveel