Questions tagged [key]

A unique identifier used to retrieve a paired value. Used in hash tables and databases.

Keys In General

A "key" is unique identifier used to retrieve a paired value. In an associative data structure such as hashtable/hashmap or balanced tree, as in a database, each value is paired with a key; an arbitrary value can be retrieved given its key.

In opposition to an array index, a key doesn't necessarily determine the physical position of the value in the data structure.


Keys in Relational Databases

Definition

  • A "superkey" is any set of attributes that, when taken together, uniquely identify rows in the table.
  • A minimal1 superkey is called "candidate key", or just "key".

1 That is, a superkey that would stop being unique (and therefore, being a superkey) if any of the attributes were removed from it.

Kinds of Keys

All keys are logically equivalent, but one of them is chosen as "primary", for historical reasons and convenience. The remaining keys are called "alternate".

In addition to that, "natural" keys can be distinguished from "surrogate" keys, based on their "meaning".

Keys and Indexes

A Key is a different concept from an index. A Key is a logical concept that changes the meaning of data, which the index doesn't. An index merely changes the time needed to manipulate the data, shortening it significantly if used properly.

An index can exist on non-key columns. Conversely, a key can exist on non-indexed columns, although this is usually forbidden in practice, for performance reasons.

Keys and Foreign Keys

A foreign key references a key. The foreign key itself doesn't have to be a key.

Keys and Tables

In relational databases, a "table" is a physical representation of the mathematical concept of a "relation", which is a set. A set either contains an element or it doesn't. It cannot contain the same element multiple times. If there isn't at least one key in the table, then the same row can exist multiple times in the table, so the table no longer represents a set and therefore no longer represents a relation.

In other words, a database without keys is not relational database.

9456 questions
3
votes
4 answers

Manipulate Ruby hash

Using Ruby I need to convert this... {"30"=>["Morgan", ["lib1", "lib2"]], "31"=>["Morgan", ["lib9", "lib2", "lib3"]], "32"=>["Gary", ["lib1", "lib2"]], "33"=>["Morgan", ["lib1"]], "34"=>["Morgan", []], "35"=>["Morgan", []], …
cymorg
  • 437
  • 1
  • 8
  • 15
3
votes
1 answer

Hbase searching by part of a key?

To better illustrate the question i will start with an exemple. Lets say, you have 3 tables : Students (2 Million rows) TestResults (100 Million rows) Test (100 000 rows). We group all the relevant data and add a denormalized table named…
Anton
  • 1,181
  • 2
  • 17
  • 27
3
votes
2 answers

iOS not key value coding compliant uitableview

I have a UIViewController with a UITableView inside of it. The UIViewController is not a UITableViewController, since there are other things on the view. If I don't hook up any outlets, the empty table appears on the view along with other things,…
syzygy
  • 1,356
  • 3
  • 16
  • 28
3
votes
2 answers

Convert Windows registry key path to string?

The straight WIN32API program I'm writing (no MFC, no .NET) uses the registry. Should a registry error occur, I'd like to print the full path of the key that failed. HKEY_CLASSES_ROOT, HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, and…
jcwren
  • 33
  • 6
3
votes
2 answers

SortedMap Key Persistance in Hibernate

I'm hoping someone can help me with my hibernate issue as I've been banging my head against Google for around an hour without result. So the issue is that I have a SortedMap in a class, using Integer as the Key (and its natural built-in compareTo…
DavidH
  • 223
  • 2
  • 13
3
votes
4 answers

Should I use a map or a set if my key is part of my value?

In C++, I have an class which is ordered by its name which is a std::string. I wish to only have one per each unique name in either a std::map or std::set. I could use a std::set since the operator< will order my instances by their name, however, I…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
3
votes
1 answer

Repeated input by holding down key in Emacs

How to lower/remove the delay, and speed up the insertion of additional keys on holding down a key? For instance: if you want to type a long "ffffffffffffff" sequence, when you do not care how many f's exactly, it takes quite some time when holding…
PascalVKooten
  • 20,643
  • 17
  • 103
  • 160
3
votes
1 answer

access array key with registered trademark

I am trying to access an array value by using a key. My code works fine except when there is a registered trademark in the key. How do I get around this? $map = array( 'Education'=>'643', 'STORMS®'=>'644', ); print $csv_line[$i]; //…
user1637231
  • 151
  • 10
3
votes
1 answer

How to generate an ssh key for logging into a server without a password

I have used servers on amazon AWS where they send me a public key .pem file and when I ssh in, all I have to do is: ssh -i key.pem user@server I now have a server of my own and am trying to figure out how I can do this with my server so I can…
justspamjustin
  • 1,730
  • 3
  • 19
  • 30
3
votes
0 answers

Restkit how to do mapping (to many) relationships by primary key

I've seen from a changes for Restkit that was commited about 6 months ago -- that Restkit supports mapping JSON structures with arrays of foreign keys: supports structure such as: { items: [{id: 1}, {id: 2}, {id: 3}], itemgroups: [{items: [1,…
Jeffery Li
  • 565
  • 1
  • 4
  • 13
3
votes
4 answers

Generate random "key" thanks to a String unseen by the user

I am looking for the best way to perform the following the current task in java (on windows) : Thanks to a specific String entered by the user, create a random other String/Key (alpha numeric) "inside" the program, and invisible by the user. The key…
Arsenic
  • 343
  • 2
  • 13
3
votes
1 answer

converting a string to Keys in C#

Lets say we store KeyCode value as a string. How do you convert it back to KeyCode? For example, I've captured a key on keydown event: string modifier = e.Modifiers.ToString(); // Control string key_string = e.KeyCode.ToString(); // D1 How to do…
Alex
  • 4,607
  • 9
  • 61
  • 99
3
votes
1 answer

Retrieving raw private key from openssl_pkey_get_private()

I've been spending quite some time trying to figure out how exactly to retrieve the raw private key data from openssl_pkey_get_private() using a passphrase. I feel like there's a simple thing I am missing. Here's my code: $config = array( …
Matt White
  • 145
  • 1
  • 2
  • 7
3
votes
3 answers

What mysql indexes should I use with this query?

SELECT * FROM items WHERE caption LIKE 'name%' AND type = 'private' OR owner LIKE 'name%' type = 'private' ORDER BY uses DESC LIMIT 40; Possible keys: items_caption,items_owner,items_type Key: items_uses (Got these by using the explain command) It…
3
votes
1 answer

How can I generate an API Key in My own Controller in Codeigniter

Just want to mention that I am really a newbie in API development (concepts, structure, best practices) I am not nearly familiar with it at all, so please excuse my pathetic stupid question if you find it to be, I'm using Phil Sturgeon's REST API…
Jerric Calosor
  • 95
  • 1
  • 1
  • 11
1 2 3
99
100