If a field in a table that has a non-primary key points to a primary key in a table, the field is called a foreign key.You can have multiple foreign keys in a single table.The default effect of a
Tags: allow span to add strict nod keep data repeating mysq data1, definition: If one table has one field pointing to the primary key of another table, the primary key field in the child table is called the foreign key. Multiple
key are defined to maintain the integrity of the relational database. The following is a summary:
A primary key is a unique identifier that can be used to determine a record. For example, a record contains an ID card number, name, and age. The ID card number is the only one that can identify you, and other IDS can be duplicated. Therefore, the ID card number is the primary
Several operation options for Oracle Foreign Key constraint (Foreign Key)
Relational databases are based on data tables and relationships. A data table organizes data in a DBMS based on a two-dimensional relationship, establishes associations between data tables, and builds a realistic object model. The primary and
tableThe Orders table is created when the following SQL creates the "p_id" column on a foreign key:
MySQL's:
CREATE TABLE Orders ( o_id int not NULL, OrderNo int not NULL, p_id int, PRIMARY KEY (o_id), FO Reign KEY (p_id) REFERENCES Persons (p_id) ) SQL server/oracle/ms A
Label:Foreign keys have the mechanism of maintaining data integrity and consistency, and have a good check effect on business processing. 1. The table engine must be INNODB,MYISAM not supported 2, foreign keys must be indexed (can be normal, primary key, unique, not established in advance will automatically create a normal index), you want to use the foreign
NULL, `updated_time` datetime DEFAULT NULL, `level` int(11) NOT NULL DEFAULT '0', `description` varchar(40) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id_index_1` (`id`) USING HASH ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
Next, we need to associate product. sid to sealer. id to associate the primary and Foreign keys of the Parent and Child
First look at the definitions of the various keys:
Super Key: An attribute set that uniquely identifies a tuple in a relationship is called a super key for a relational pattern
candidate Keys (Candidate key): A key that does not contain extra attributes is called a candidate key
(node_id) references nodes (ID) on DELETE cascade,
primary key (ID)
) ENGINE = InnoDB ;
The node_id field now acts as a ' link ' or ' pointer ' back to the nodes table. This comes in very handy in all sorts of the database work (as you'll see soon). That's all of you has to does to the create a foreign key in
of the relational database, summarizing: A primary key is a unique identifier that determines a record, for example, a record that includes a social security number, name, and age. The ID number is the only person who can identify you, others may have duplicates, so the ID number is the primary key. A foreign key is
the students ' table.The course number in the results table is the foreign key of the curriculum.Defining primary and foreign keys is primarily to maintain the integrity of the relational database, summarizing:1. A primary key is a unique identifier that determines a record, for example, a record that includes an iden
are defined primarily to maintain the integrity of the relational database, summarizing:
A primary key is a unique identifier that determines a record, for example, a record includes an ID number, a name, and an age. The ID number is the only one who can be sure of you, and others may have duplicates, so the ID number is the primary key.
A foreign
Defining Data Tables
If a computer manufacturer, its database is stored in the machine and accessories product information. The table used to keep the whole product information is called a Pc, and the table used to hold the information of accessory supply is called parts.
There is a field in the PC table that describes the CPU model used by the computer;
There is a field in the Parts table that describes
Label:the role of foreign keys The main role of foreign keys is to maintain data consistency and integrity. About foreign keys, I have some of my own understanding, but I do not know whether it is correct, for example to express my view: If you need to build a table, what kind of table it? A student's personal information table for a class: So in the design, you
, the foreign key is more convenient.
4, about convenience, according to my project, programmers do have a reflection, mainly in the debugging of the data input trouble: If the data can violate referential integrity, then the referential integrity itself is not the reputation of business conflict, this time should not be used to trigger the futures program; otherwise, the data is wrong, There should be no
ID and name of the corrupt official. There is also a corrupt official mistress table, note that a corrupt official is not necessarily only a mistress, it has a 2345 milk is very normal, so in the corrupt officials table inside a data, corresponding to Mistress list may haveMultiple records, which is a one-to-many relationship that is associated with a corrupt official ID. Referential integrity: When a foreign key
(that is, the primary key in the table does not have a foreign key associated with it). index is used to quickly look for records that have a specific value. Mainly for the convenience of retrieval, is to speed up access, according to certain rules created, generally play the role of sorting. The so-called Uniqueness
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.