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
1 answer

SML - Creating dictionary that maps keys to values

I need to create a dictionary in sml, but I am having extreme difficulty with an insert function. type dict = string -> int option As an example, here is the empty dictionary: val empty : dict = fn key => NONE Here is my implementation of…
user44438
  • 35
  • 1
  • 4
3
votes
3 answers

How is the return value of __hash__ used?

Suppose I write a class, but don't define a __hash__ for it. Then __hash__(self) defaults to id(self) (self's memory address), according to the documentation. However I don't see in the documentation, how this value is being used. So if my __hash__…
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241
3
votes
4 answers

Python: How to access the dictionary that has specific key-values in a list

I have a list of dictionaries: [ {"START":"Denver", "END":"Chicago", "Num":0}, {"START":"Dallas", "END":"Houston", "Num":3}, {"START":"Virginia", "END":"Boston", "Num":1}, {"START":"Washington", "END":"Maine", "Num":7} ] How do I access the…
alwbtc
  • 28,057
  • 62
  • 134
  • 188
3
votes
1 answer

Hibernate/JPA - Is possible to use @Id and @EmbededId at same time?

i´m a little confused to add a business key in my entity mapping. All entities uses Long as a Id, but now i have to create a composite Id, my doubt is, can i mixed @Id and @EmbeddedId together or only the embedded object must be the Id alone? Here…
LottaLava
  • 889
  • 1
  • 9
  • 21
3
votes
1 answer

SQL Server - obtain error parameters in catch

Possible Duplicate: How do I find out the _exact_ error from SQL Server One of our clients desires custom error messages upon UNIQUE KEY violations. Given the following scenario: CREATE TABLE [dbo].[Pip] ( id int IDENTITY(1,1) NOT NULL, …
sanderd
  • 809
  • 4
  • 21
3
votes
2 answers

Composite Foreign Key from Multiple Tables

I am building the schema of one of my databases. I have two of the following tables... CREATE TABLE User( userID INT AUTO_INCREMENT, ... PRIMARY KEY(userID) ); CREATE TABLE Tool( toolID INT AUTO_INCREMENT, ... PRIMARY KEY(toolID) ) I want to…
user625665
  • 45
  • 1
  • 6
3
votes
0 answers

Retrieve value of a map using a dynamic key in XSLT

I am forming an xsl where I am forming a map with keys and values. 2.1 3.1 4.1 5.1
3
votes
1 answer

Alt-Tab issue on Windows Activation in WPF

In my app, I have a special action mapped to the tab key. The problem is that when you use the short-cut Alt-Tab to switch between different apps, my app gets a tab key (but not the Alt key) when it becomes activated, which I'd like to avoid. This…
newman
  • 6,841
  • 21
  • 79
  • 126
3
votes
1 answer

Heroku database and amazon s3 encryption key storage for HIPAA compliance

I was hoping to get a recommendation on the best way to store a database encryption key for HIPAA compliance as well as Amazon S3 file storage security. I have been searching stackoverflow and googling in general, but I just can't quite get a solid…
3
votes
3 answers

Combine Hash Tables With the Same Keys but Different Values in Powershell

Okay, I have some hash tables I need to combine using PowerShell. Here is an example of the format: $table1 = @{"A" = "1,2"; "B" = "3,4"; "C" = "5,6"} $table2 = @{"A" = "3"; "B" = "5"; "C" = "7"} I…
E_MAN
  • 31
  • 1
  • 2
3
votes
2 answers

Converting numbers in Ada

I am wondering how to convert an integer to a long_integer and a long_integer to a Positive_Count. Every way I have tried has given me and error even though the conversion should be easy in that instance. For example, doing long :=…
user1279914
  • 185
  • 1
  • 5
  • 19
3
votes
3 answers

C# Plugin Architecture with Strong Names: A Misunderstanding

I have a server executable that talks to Active Directory to retrieve user information. In addition to AD, this exe allows customers to write their own plugins to talk to custom user directories. This executable is strongly named. Is the following a…
Alan
  • 45,915
  • 17
  • 113
  • 134
3
votes
1 answer

Ruby OpenSSL AES generate random key

I have an elementary problem that I can't seem to figure out. I'm trying to generate a random key in AES-256-CBC that can be used to encrypt/decrypt data. Here is what i'm doing: require 'openssl' cipher =…
Sean
  • 1,078
  • 14
  • 25
3
votes
1 answer

AES and key length error

I am trying to get this code to work. It is from Cryptopp AES Demonstrates encryption and decryption using AES in CTR The only difference is, that I created the function encryptAES and decryptAES and inserted the code. It works without creating…
nt2005
  • 69
  • 1
  • 2
  • 8
3
votes
2 answers

Really weird collision in hash algorithm: coincidence or error?

I made a hash algorithm that uses MD5 for some low-security key generation. Basically, it takes the characters of a String and sums their indexed products, then takes the modulo of a random number, before MD5-ing that. In Java: BigInteger bi =…
wchargin
  • 15,589
  • 12
  • 71
  • 110