IndexIntroductionA primary key follows these rulesReferential integrityIntroductionA primary key is a unique data element that allows the user to identify any part of the record. When you specify a primary key constraint for a table, the Database Engine enforces data exclusivity by automatically creating a unique index for the primary key columns. This is useful for identifying the data you need quickly and efficiently. For example, you can identify a student in a database full of students with just their ID instead of their details. Say no to plagiarism. Get a tailor-made essay on "Why Violent Video Games Shouldn't Be Banned"? Get an original essayA primary key follows these rulesA table can only have one primary key, usually it is the "ID" key. It cannot exceed 16 columns and a key length of 900 bytes. The index generated by a primary key constraint cannot cause the number of indexes on the table to exceed 999 non-clustered indexes and 1 clustered index. If cluster or noncluster is not specified for a primary key constraint, cluster is used if there is no clustered index on the table. All columns defined within a primary key constraint must be defined as non-null. If Null is not specified, all columns participating in a primary key constraint will have their Null value set to non-null. If a primary key is defined in a column of user-defined CLR type, the type implementation must support binary sorting. A foreign key is a column or combination of columns used to establish and enforce a link between data in two tables to control what data can be stored in the foreign key table. A link is created between two tables when the column or columns that contain the primary key value for one table reference the column or columns of another table. This column becomes a foreign key in the second table. Referential integrity Referential integrity is a relational database concept, according to which relationships between tables must always be consistent. In other words, any foreign key field must agree with the primary key referenced by the foreign key. Therefore, any changes to the primary key field must be applied to all foreign keys or not at all. The same restriction also applies to foreign keys as any updates (but not necessarily deletions) must be propagated to the primary master key. Please note: this is just an example. Get a custom paper from our expert writers now. Get a custom essay for For example, deleting a record that contains a value referenced by a foreign key in another table would compromise referential integrity. Some relational database management systems can enforce referential integrity, even deleting foreign key rows to maintain integrity or returning an error and not performing the deletion. The method used can be determined by a referential integrity constraint defined in a data dictionary.
tags