To Generate A Surrogate Key Microsoft Access Uses A Quizlet
To Generate A Surrogate Key Microsoft Access Uses A Quizlet 3,5/5 564 reviews

Posted Jan 31, 2011

Cisco crypto key generate rsa command card. By Gregory A. Larsen

  1. Jun 06, 2006  Now space usage. Table with surrogate key uses 1630 + 256 + 384 = 2270 blocks. Table without surrogate key uses 1566 + 384 = 1950 blocks (although it has allocated the same number of blocks for table probably due to auto segmentspacemanagement). Most insert time gain was 25%, but due to so small numbers miscalculation could be rather high.
  2. Aug 10, 2009 yah, but he has a type 2 table, you would want it to be persisted and these surroget keys would be populated in other tables. Creating one in the dsv could be bad, what if new values are inserted and the keys change?

When designing a database to support applications you need to consider how you are going to handle primary keys. This article explores natural and surrogate keys, and discusses the pros and cons of each, allowing you to determine what makes the best sense in your environment when you are designing your databases.

When designing a database to support applications you needto consider how you are going to handle primary keys. There are two schoolsof thought, or maybe three. There are those that say primary keys shouldalways be a made up key, or what is commonly called a surrogate key. Otherssay there are good reasons to use real data as a key value; this type of key isknown as natural key. The third group is those that design their databases sotheir primary keys are a combination of natural and surrogate keys. In thisarticle, I’m going explore natural and surrogate key, and discuss the pros andcons of each. This will allow you to determine what makes best sense in yourenvironment when you are designing your databases.

Natural Key verses Surrogate Key

Study 77 CIS Final Part II flashcards from DF S. On StudyBlue. If a table has multiple candidate keys and one of those candidate keys is a composite key, the table can have based on this composite candidate key, even when the primary key chosen is a single attribute.

When you design tables with SQL Server, a table typically hasa column or a number of columns that are known as the primary key. The primarykey is a unique value that identifies each record. Sometimes the primary key ismade up of real data and these are normally referred to as natural keys, whileother times the key is generated when a new record is inserted into a table. When a primary key is generated at runtime, it is called a surrogate key. A surrogatekey is typically a numeric value. Within SQL Server, Microsoft allows you todefine a column with an identity property to help generate surrogate key values.

Before I talk about the pros and cons of natural andsurrogate keys, let me first expand a little more on each type of key. By doingthis you will have a better understanding of each of these two types of keys,and will have a more solid foundation to determine which type of key you shoulduse in your database design.

A natural key is a single column or set of columns thatuniquely identifies a single record in a table, where the key columns are madeup of real data. When I say “real data” I mean data that has meaning andoccurs naturally in the world of data. A natural key is a column value thathas a relationship with the rest of the column values in a given data record. Here are some examples of natural keys values: Social Security Number, ISBN, andTaxId.

A surrogate key like a natural key is a column that uniquelyidentifies a single record in a table. But this is where the similaritystops. Surrogate keys are similar to surrogate mothers. They are keys thatdon’t have a natural relationship with the rest of the columns in a table. Thesurrogate key is just a value that is generated and then stored with the restof the columns in a record. The key value is typically generated at run timeright before the record is inserted into a table. It is sometimes alsoreferred to as a dumb key, because there is no meaning associated with thevalue. Surrogate keys are commonly a numeric number.

Now that you have an understanding of the difference betweenthese two types of keys I will explore why you might use one key over theother. In the world of data architects, there is much debate over when it isappropriate to use a natural key and when a better solution would be to use asurrogate key. As already stated there are mainly just twodifferent camps. Some say you should always use a natural key and the otherssay a surrogate key is best. I suppose there is also a third camp that uses acombination of both natural keys and surrogate keys in their database design. Rather than state my opinion on which is best I’ll give you the pros and consof uses each and then you can decide with is best for your design.

Surrogate Key Pros and Cons

A definite design and programming aspect of working with databases is built on the concept that all keys will be supported by the use surrogate keys. To understand these programming aspects better, review these pros and cons of using surrogate keys.

Pros:

Microsoft Access Benefits

  • The primary key has no business intelligence built into it.Meaning you cannot derive any meaning, or relationship between the surrogatekey and the rest of the data columns in a row.
  • If your business rules change, which would require you to updateyour natural key this can be done easily without causing a cascade effectacross all foreign key relationships. By using a surrogate key instead of anatural key the surrogate key is used in all foreign key relationships. Surrogatekeys will not be updated over time.
  • Surrogate keys are typically integers, which only require 4 bytesto store, so the primary key index structure will be smaller in size than theirnatural key counter parts. Having a small index structure means betterperformance for JOIN operations.

Cons:

  • If foreign key tables use surrogate keys then you will berequired to have a join to retrieve the real foreign key value. Whereas if theforeign key table used a natural key then the natural key would be already beincluded in your table and no join would be required. Of course this I onlytrue if you only needed the natural key column returned in your query
  • Surrogate keys are typically not useful when searching for datasince they have no meaning.

Natural Key Pros and Cons

Having natural keys as indexes on your tables mean you willhave different programming considerations when building your applications. Youwill find that pros and cons for natural keys to be just the opposite as thepros and cons for surrogate keys.

Pros:

  • Will require less joins when you only need to return the keyvalue of a foreign key table. This is because the natural key will already beimbedded in your table.
  • Easier to search because natural keys have meaning and will bestored in your table. Without the natural key in your table, a search for recordsbased on a natural key would require a join to the foreign key table to get thenatural key.

Cons:

  • Requires much more work to change a natural key, especially whenforeign relationship have been built off the natural key.
  • Your primary key index will be larger because natural keys aretypically larger in size then surrogate keys.
  • Since natural keys are typically larger in size then surrogatekeys and are strings instead of integers joins between two tables on a naturalkey will take more time.

What Kind of Database Designer Are You?

There is much debate in the world of data modeling over whatkind of data should be used to support primary keys. There are some puristthat say all primary key should be surrogate keys, no matter how small thenatural key, or the fact that the natural key will never be updated. Other sayyou need to use natural keys because they make coding your application just somuch easier. When you design your databases, you need to decide what works bestin your environment. What kind of database designer are you and into which design camp do you fall?

» See All Articles by ColumnistGregory A. Larsen





Latest Forum Threads
MS SQL Forum
TopicByRepliesUpdated
SQL 2005: SSIS: Error using SQL Server credentialspoverty3August 17th, 07:43 AM
Need help changing table contentsnkawtg1August 17th, 03:02 AM
SQL Server Memory confifurationbhosalenarayan2August 14th, 05:33 AM
SQL Server – Primary Key and a Unique Keykatty.jonh2July 25th, 10:36 AM


A surrogate key (or synthetic key, entity identifier, system-generated key, database sequence number, factless key, technical key, or arbitrary unique identifier[citation needed]) in a database is a unique identifier for either an entity in the modeled world or an object in the database. The surrogate key is not derived from application data, unlike a natural (or business) key which is derived from application data.[1]

Definition[edit]

There are at least two definitions of a surrogate:

Surrogate (1) – Hall, Owlett and Todd (1976)
A surrogate represents an entity in the outside world. The surrogate is internally generated by the system but is nevertheless visible to the user or application.[2]
Surrogate (2) – Wieringa and De Jonge (1991)
A surrogate represents an object in the database itself. The surrogate is internally generated by the system and is invisible to the user or application.

The Surrogate (1) definition relates to a data model rather than a storage model and is used throughout this article. See Date (1998). Fable 3 activation key generator pc.

An important distinction between a surrogate and a primary key depends on whether the database is a current database or a temporal database. Since a current database stores only currently valid data, there is a one-to-one correspondence between a surrogate in the modeled world and the primary key of the database. In this case the surrogate may be used as a primary key, resulting in the term surrogate key. In a temporal database, however, there is a many-to-one relationship between primary keys and the surrogate. Since there may be several objects in the database corresponding to a single surrogate, we cannot use the surrogate as a primary key; another attribute is required, in addition to the surrogate, to uniquely identify each object.

Although Hall et al. (1976) say nothing about this, others[specify] have argued that a surrogate should have the following characteristics:

  • the value is unique system-wide, hence never reused
  • the value is system generated
  • the value is not manipulable by the user or application
  • the value contains no semantic meaning
  • the value is not visible to the user or application
  • the value is not composed of several values from different domains.

Surrogates in practice[edit]

In a current database, the surrogate key can be the primary key, generated by the database management system and not derived from any application data in the database. The only significance of the surrogate key is to act as the primary key. It is also possible that the surrogate key exists in addition to the database-generated UUID (for example, an HR number for each employee other than the UUID of each employee).

A surrogate key is frequently a sequential number (e.g. a Sybase or SQL Server 'identity column', a PostgreSQL or Informixserial, an Oracle or SQL ServerSEQUENCE or a column defined with AUTO_INCREMENT in MySQL). Some databases provide UUID/GUID as a possible data type for surrogate keys (e.g. PostgreSQL UUID or SQL Server UNIQUEIDENTIFIER).

Having the key independent of all other columns insulates the database relationships from changes in data values or database design (making the database more agile) and guarantees uniqueness.

In a temporal database, it is necessary to distinguish between the surrogate key and the business key. Every row would have both a business key and a surrogate key. The surrogate key identifies one unique row in the database, the business key identifies one unique entity of the modeled world. One table row represents a slice of time holding all the entity's attributes for a defined timespan. Those slices depict the whole lifespan of one business entity. For example, a table EmployeeContracts may hold temporal information to keep track of contracted working hours. The business key for one contract will be identical (non-unique) in both rows however the surrogate key for each row is unique.

SurrogateKeyBusinessKeyEmployeeNameWorkingHoursPerWeekRowValidFromRowValidTo
1BOS0120John Smith402000-01-012000-12-31
56P0000123Bob Brown251999-01-012011-12-31
234BOS0120John Smith352001-01-012009-12-31

Some database designers use surrogate keys systematically regardless of the suitability of other candidate keys, while others will use a key already present in the data, if there is one.

Some of the alternate names ('system-generated key') describe the way of generating new surrogate values rather than the nature of the surrogate concept.

Approaches to generating surrogates include:

  • Universally Unique Identifiers (UUIDs)
  • Globally Unique Identifiers (GUIDs)
  • Object Identifiers (OIDs)
  • Sybase or SQL Server identity column IDENTITY OR IDENTITY(n,n)
  • OracleSEQUENCE, or GENERATED AS IDENTITY (starting from version 12.1)[3]
  • SQL ServerSEQUENCE (starting from SQL Server 2012)[4]
  • PostgreSQL or IBM Informix serial
  • MySQLAUTO_INCREMENT
  • SQLiteAUTOINCREMENT
  • AutoNumber data type in Microsoft Access
  • AS IDENTITY GENERATED BY DEFAULT in IBM DB2
  • Identity column (implemented in DDL) in Teradata
  • Table Sequence when the sequence is calculated by a procedure and a sequence table with fields: id, sequenceName, sequenceValue and incrementValue

Advantages[edit]

Immutability[edit]

Surrogate keys do not change while the row exists. This has the following advantages:

  • Applications cannot lose their reference to a row in the database (since the identifier never changes).
  • The primary or natural key data can always be modified, even with databases that do not support cascading updates across related foreign keys.

Requirement changes[edit]

Attributes that uniquely identify an entity might change, which might invalidate the suitability of natural keys. Consider the following example:

An employee's network user name is chosen as a natural key. Upon merging with another company, new employees must be inserted. Some of the new network user names create conflicts because their user names were generated independently (when the companies were separate).

In these cases, generally a new attribute must be added to the natural key (for example, an original_company column).With a surrogate key, only the table that defines the surrogate key must be changed. With natural keys, all tables (and possibly other, related software) that use the natural key will have to change.

Some problem domains do not clearly identify a suitable natural key. Surrogate keys avoid choosing a natural key that might be incorrect.

Performance[edit]

Surrogate keys tend to be a compact data type, such as a four-byte integer. This allows the database to query the single key column faster than it could multiple columns. Furthermore, a non-redundant distribution of keys causes the resulting b-tree index to be completely balanced. Surrogate keys are also less expensive to join (fewer columns to compare) than compound keys.

Compatibility[edit]

While using several database application development systems, drivers, and object-relational mapping systems, such as Ruby on Rails or Hibernate, it is much easier to use an integer or GUID surrogate keys for every table instead of natural keys in order to support database-system-agnostic operations and object-to-row mapping.

Uniformity[edit]

To generate a surrogate key microsoft access uses a quizlet key

When every table has a uniform surrogate key, some tasks can be easily automated by writing the code in a table-independent way.

Validation[edit]

It is possible to design key-values that follow a well-known pattern or structure which can be automatically verified. For instance, the keys that are intended to be used in some column of some table might be designed to 'look differently from' those that are intended to be used in another column or table, thereby simplifying the detection of application errors in which the keys have been misplaced. However, this characteristic of the surrogate keys should never be used to drive any of the logic of the applications themselves, as this would violate the principles of Database normalization.

Disadvantages[edit]

Disassociation[edit]

The values of generated surrogate keys have no relationship to the real-world meaning of the data held in a row. When inspecting a row holding a foreign key reference to another table using a surrogate key, the meaning of the surrogate key's row cannot be discerned from the key itself. Every foreign key must be joined to see the related data item. If appropriate database constraints have not been set, or data imported from a legacy system where referential integrity was not employed, it is possible to have a foreign-key value that does not correspond to a primary-key value and is therefore invalid. (In this regard, C.J. Date regards the meaninglessness of surrogate keys as an advantage. [5])

To discover such errors, one must perform a query that uses a left outer join between the table with the foreign key and the table with the primary key, showing both key fields in addition to any fields required to distinguish the record; all invalid foreign-key values will have the primary-key column as NULL. The need to perform such a check is so common that Microsoft Access actually provides a 'Find Unmatched Query' wizard that generates the appropriate SQL after walking the user through a dialog. (It is, however, not too difficult to compose such queries manually.) 'Find Unmatched' queries are typically employed as part of a data cleansing process when inheriting legacy data.

Surrogate keys are unnatural for data that is exported and shared. A particular difficulty is that tables from two otherwise identical schemas (for example, a test schema and a development schema) can hold records that are equivalent in a business sense, but have different keys. This can be mitigated by NOT exporting surrogate keys, except as transient data (most obviously, in executing applications that have a 'live' connection to the database).

When surrogate keys supplant natural keys, then domain specific referential integrity will be compromised. For example, in a customer master table, the same customer may have multiple records under separate customer IDs, even though the natural key (a combination of customer name, date of birth, and E-mail address) would be unique. To prevent compromise, the natural key of the table must NOT be supplanted: it must be preserved as a unique constraint, which is implemented as a unique index on the combination of natural-key fields.

Query optimization[edit]

Relational databases assume a unique index is applied to a table's primary key. The unique index serves two purposes: (i) to enforce entity integrity, since primary key data must be unique across rows and (ii) to quickly search for rows when queried. Since surrogate keys replace a table's identifying attributes—the natural key—and since the identifying attributes are likely to be those queried, then the query optimizer is forced to perform a full table scan when fulfilling likely queries. The remedy to the full table scan is to apply indexes on the identifying attributes, or sets of them. Where such sets are themselves a candidate key, the index can be a unique index.

These additional indexes, however, will take up disk space and slow down inserts and deletes.

Normalization[edit]

Surrogate keys can result in duplicate values in any natural keys. To prevent duplication, one must preserve the role of the natural keys as unique constraints when defining the table using either SQL's CREATE TABLE statement or ALTER TABLE ..ADD CONSTRAINT statement, if the constraints are added as an afterthought.

Business process modeling[edit]

Because surrogate keys are unnatural, flaws can appear when modeling the business requirements. Business requirements, relying on the natural key, then need to be translated to the surrogate key. A strategy is to draw a clear distinction between the logical model (in which surrogate keys do not appear) and the physical implementation of that model, to ensure that the logical model is correct and reasonably well normalised, and to ensure that the physical model is a correct implementation of the logical model.

Inadvertent disclosure[edit]

Proprietary information can be leaked if sequential key generators are used. By subtracting a previously generated sequential key from a recently generated sequential key, one could learn the number of rows inserted during that time period. This could expose, for example, the number of transactions or new accounts per period. There are a few ways to overcome this problem:

  • Increase the sequential number by a random amount.
  • Generate a random key such as a UUID

Inadvertent assumptions[edit]

Sequentially generated surrogate keys can imply that events with a higher key value occurred after events with a lower value. This is not necessarily true, because such values do not guarantee time sequence as it is possible for inserts to fail and leave gaps which may be filled at a later time. If chronology is important then date and time must be separately recorded.

See also[edit]

References[edit]

Citations[edit]

  1. ^'What is a Surrogate Key? - Definition from Techopedia'. Techopedia.com. Retrieved 2020-02-21.
  2. ^P A V Hall, J Owlett, S J P Todd, 'Relations and Entities', Modelling in Data Base Management Systems (ed GM Nijssen),North Holland 1976.
  3. ^http://docs.oracle.com/database/121/SQLRF/statements_7002.htm#SQLRF01402
  4. ^https://msdn.microsoft.com/en-us/library/ff878091.aspx
  5. ^ C.J. Date. The primacy of primary keys. From 'Relational Database Writings, 1991-1994. Addison-Wesley, Reading, MA.

Microsoft Access Uses In Business

Sources[edit]

  • This article is based on material taken from the Free On-line Dictionary of Computing prior to 1 November 2008 and incorporated under the 'relicensing' terms of the GFDL, version 1.3 or later.

Microsoft Access Tutorial

  • Nijssen, G.M. (1976). Modelling in Data Base Management Systems. North-Holland Pub. Co. ISBN0-7204-0459-2.
  • Engles, R.W.: (1972), A Tutorial on. CiteSeerX10.1.1.16.3195.Cite journal requires journal= (help)
  • Date, C. J. (1998). 'Chapters 11 and 12'. Relational Database Writings 1994–1997. ISBN0201398141.
  • Carter, Breck. 'Intelligent Versus Surrogate Keys'. Retrieved 2006-12-03.
  • Richardson, Lee. 'Create Data Disaster: Avoid Unique Indexes – (Mistake 3 of 10)'. Archived from the original on 2008-01-30. Retrieved 2008-01-19.
  • Berkus, Josh. 'Database Soup: Primary Keyvil, Part I'. Retrieved 2006-12-03.

To Generate A Surrogate Key Microsoft Access Uses A Quizlet Key

Retrieved from 'https://en.wikipedia.org/w/index.php?title=Surrogate_key&oldid=949211050'