Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Relational database
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Constraints== Constraints are often used to make it possible to further restrict the domain of an attribute. For instance, a constraint can restrict a given integer attribute to values between 1 and 10. Constraints provide one method of implementing [[business rules]] in the database and support subsequent data use within the application layer. SQL implements constraint functionality in the form of [[check constraint]]s. Constraints restrict the data that can be stored in [[relation (database)|relations]]. These are usually defined using expressions that result in a <!-- do not change the capitalization of this link without first consulting, and replying to the talk page. Any such edits will be reverted. -->[[Boolean data type|Boolean]] value, indicating whether or not the data satisfies the constraint. Constraints can apply to single attributes, to a tuple (restricting combinations of attributes) or to an entire relation. Since every attribute has an associated domain, there are constraints ('''domain constraints'''). The two principal rules for the relational model are known as '''[[entity integrity]]''' and '''[[referential integrity]]'''. ===Primary key=== {{Main|Unique key|Primary key}} Every [[Relation (database)|relation]]/table has a primary key, this being a consequence of a relation being a [[Set (mathematics)|set]].{{Sfnp|Date|1984|p=268}} A primary key uniquely specifies a tuple within a table. While natural attributes (attributes used to describe the data being entered) are sometimes good primary keys, [[surrogate key]]s are often used instead. A surrogate key is an artificial attribute assigned to an object which uniquely identifies it (for instance, in a table of information about students at a school they might all be assigned a student ID in order to differentiate them). The surrogate key has no intrinsic (inherent) meaning, but rather is useful through its ability to uniquely identify a tuple. Another common occurrence, especially in regard to N:M cardinality is the [[Compound key|composite key]]. A composite key is a key made up of two or more attributes within a table that (together) uniquely identify a record.<ref>{{Cite book |last1=Connolly |first1=Thomas M |title=Database systems: a practical approach to design, implementation, and management |last2=Begg |first2=Carolyn E |publisher=Pearson |year=2015 |isbn=978-1-292-06118-4 |edition=global |location=Boston Columbus Indianapolis |pages=416}}</ref> ===Foreign key=== {{Main|Foreign key}} Foreign key refers to a field in a relational table that matches the primary key column of another table. It relates the two keys. Foreign keys need not have unique values in the referencing relation. A foreign key can be used to [[cross-reference]] tables, and it effectively uses the values of attributes in the referenced relation to restrict the domain of one or more attributes in the referencing relation. The concept is described formally as: "For all tuples in the referencing relation projected over the referencing attributes, there must exist a tuple in the referenced relation projected over those same attributes such that the values in each of the referencing attributes match the corresponding values in the referenced attributes." ===Stored procedures=== {{Main|Stored procedure}} A stored procedure is executable code that is associated with, and generally stored in, the database. Stored procedures usually collect and customize common operations, like inserting a [[tuple]] into a [[relation (database)|relation]], gathering statistical information about usage patterns, or encapsulating complex [[business logic]] and calculations. Frequently they are used as an [[application programming interface]] (API) for security or simplicity. Implementations of stored procedures on SQL RDBMS's often allow developers to take advantage of [[Procedural programming|procedural]] extensions (often vendor-specific) to the standard [[Declarative programming|declarative]] SQL syntax. Stored procedures are not part of the relational database model, but all commercial implementations include them. ===Index=== {{Main|Index (database)}} An index is one way of providing quicker access to data. Indices can be created on any combination of attributes on a [[relation (database)|relation]]. Queries that filter using those attributes can find matching tuples directly using the index (similar to [[Hash table]] lookup), without having to check each tuple in turn. This is analogous to using the [[Index (publishing)|index of a book]] to go directly to the page on which the information you are looking for is found, so that you do not have to read the entire book to find what you are looking for. Relational databases typically supply multiple indexing techniques, each of which is optimal for some combination of data distribution, relation size, and typical access pattern. Indices are usually implemented via [[B+ tree]]s, [[R-tree]]s, and [[Bitmap index|bitmaps]]. Indices are usually not considered part of the database, as they are considered an implementation detail, though indices are usually maintained by the same group that maintains the other parts of the database. The use of efficient indexes on both primary and foreign keys can dramatically improve query performance. This is because B-tree indexes result in query times proportional to log(n) where n is the number of rows in a table and hash indexes result in constant time queries (no size dependency as long as the relevant part of the index fits into memory).
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)