Patent ID: 8762377

Claim:
A method for setting a candidate key for a table, the method being used in an apparatus comprising a microprocessor and a storage unit electrically connected to the microprocessor, the storage unit being configured to store the table, the table recording a data amount of the table, a plurality of attributes of the table, a data distinct amount of each attribute and a data type of each attribute, the method comprising the following steps of: (a) enabling the microprocessor to generate a first attribute combination according to the attributes and the data type of each attribute, wherein the first attribute combination comprises a plurality of selected attributes, each of the selected attributes is one of the attributes, each of the selected attributes corresponds to a representation bit amount, each of the representation bit amount being used to determine the data distinct amount of the corresponding attribute; (b1) enabling the microprocessor to calculate a product of the data distinct amount of the selected attributes; (b2) enabling the microprocessor to determine that a product of the data distinct amount of the selected attributes is greater than or equal to the data amount; (c) enabling the microprocessor to generate a determination result according to an attribute number of the selected attributes of the first attribute combination; and (d) enabling the microprocessor to set the first attribute combination as the candidate key of the table according to the determination result.