+ 8
What is difference between primary and foreign key?
14 ответов
+ 15
A primary key is a column or a set of columns that uniquely identify a row in a table. A primary key should be short, stable and simple. A foreign key is a field (or collection of fields) in a table whose value is required to match the value of the primary key for a second table.
+ 13
I have a name. That is how people refer to me, so it is my primary key.
I also have a dog with a name. His name is also his primary key as I use it to call for him.
To let everyone know that it is my dog, I store a copy of his primary key as a part of myself, but since it refers to something else than me, it's a foreign key.
In other words, the primary key is unique and defines the object, while foreign keys display a relation to another object.
+ 3
A primary key is a column/s that can uniquely identify tuples in a relation ,primary key must not be null.Where as a foreign key is a column/s that has the same set or subset of values as a primary key in another relation.
+ 3
The primary key the unique column of a table that uniquely identifies rows of table.It does not contain any duplicate item and also no value is empty.
Whereas the foreign key is the column which may be more than one columns and its value is matched with the value of primary key to identify the record in another table.
+ 2
primary keys are unique identifiers for data in a table while foreign keys simply reference data in another table.
A(tableA_id, name,dataFromB)
B(tableB_id,dataStoredInB)
Take for instance the two tables above, the primary key(pk) are the tableA_id and tableB_id fields while the foreign key(fk ) is the dataFromB field that references the dataStoredInB field.
Also foreign keys do not have to be primary keys from another table they can be field from another table.
+ 2
we use primary key to identify a record of a table uniquely.And we use foreign key to identify field of a one table uniquely to row of another table.
+ 2
Tô sum up:
Primary Key is an unique value set for each row in a table, for identifying the row.
Foreign Key is a value used to reference a Primary Key from OTHER table.
+ 1
primary key contain the unique value but foreign key have contain duplicate values.
+ 1
primary key and foreign key both are unique and null value but primary key of one table will be known as the foreign key of another table.
0
primary key is a unique which is not null .it is a key which uniquely identifys the table.forgien key is the referntial integrity.suppose take an real life example.student table contain rollnumber,name,branch.here rollnumber acts as primary key.In another table named library which contain same rollnumber a column here the rollnumber acts as a forgein key for the student table
0
when joining 2 tables there needs to be a common field in both. E.G a customer table and sales record table. the sales record table will have the details of the sale and a [customer_ID] field. the customer table will also have a [ID] field. in the customer table the [ID] field will be unique for each customer, whilst the sales record table will have potentially many of the [customer_ID]s for different sales to the same customer. In the customer table the ID field is unique and is the primary key. the matching field in the sale record table is not unique in that table and is the foreign key.
so unique in a table = primary,
not unique in a table = foreign
0
primary key mainly used for identifying any field value uniquely and it has also removed the use of two constraint NOT NULL and UNIQUE while foreign key relates the two tables one table's primary key may be foreign in another table
0
primary key provide two conditions.
1 not null
2 data should be unique.
foreign key provide references of other table.