It also means that if John Smith’s user page can be accessed via a URL or API call which contains that id value of 1500, then there’s a good chance simply changing the value to another number, such as 1499 or 1501, will expose the page of another user that may not want their page accessed by this visitor. First, it indicates that there are likely a minimum of at least 1499 other users in the system, or were at some point. John Smith) is the value 1500, this exposes a bit of information already. If a malicious person discovers that the id attribute of a given user (e.g. However, most developers agree that this practice is out of date and exposes unnecessary security flaws for the system when used for some tables that represent certain data.įor example, imagine all User records are assigned an auto-incremented primary key value, know as the id attribute. This simply means that the database engine itself automatically assigns each new record in that table a unique primary key value that is incrementally larger than all previous values. It’s also briefly worth noting that many database systems are setup in such a way that every table has a primary key that is both numeric and is also auto-incremented. For example, imagine a User gets a new email address, which then causes all past primary key associations made using the old email address to become invalid when using the new email address.įor this reason (among others), most primary keys use a number or unique string, such as a (). In practice, the primary key attribute is also marked as NOT NULL in most databases, meaning that attribute must always contain a value for the record to be inserted into the table.Īs an example, either the email or username simple keys could be assigned the designation of the primary key, but typically it is best practice to set the primary key to an attribute that isn’t (or couldn’t) be changed by either the business logic or even by the individual. The primary key is unique and that attribute is then used throughout the database and is accessed and passed around to other tables as the representative attribute for the data in question. Primary KeysĪ () is a key which has been chosen to be the principal (or primary) representative attribute for that row of data. For example, the system may automatically combine the last_name and year_of_birth single keys into a concatenated key, like so: smith1980. As the name implies, a concatenated key is a joining of multiple single keys. Taken one step further from simple keys are concatenated or compound keys. Unless we impose more restrictions on the key or the table, then the username attribute in the above example is a simple key. Simple KeysĪ simple key is just a key using only one single attribute in the table. A table can and often will have multiple keys, such as in the table Users both email and username could be considered keys.ĭepending on the developer or administrator you’re speaking to, you may hear about a variety of key-types and their definitions, so we’ll just cover a few different examples below and a basic definition of each. A key in a table is simply an attribute that is used to identify and access that information. To understand what a primary key is in a database table, we must first understand a little bit about non-primary keys. While many developers and database administrators may work with primary keys everyday, it is a fascinating topic to ask oneself, “What exactly is a primary key and can (or should) a database table contain multiple primary keys simultaneously?”īelow we’ll examine these questions in more detail and try to come to the reasonable and generally agreed upon consensus within the development community.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |