answersLogoWhite

0


Best Answer

primary key means unique as well as non-nullable field for a table it supposed don't have duplicate value.

foreign key means is referential field in a table meanwhile is primary key for another table.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

A primary key is a construct in a database used to uniquely identify one specific row in a table. Primary keys are frequently associated with Foreign Keys, which are used to correlate data in one database table to another database table. For example, let's say I have two database tables, one for Names, another for Telephone Numbers. Table: Names
ID Name
-- ----
01 Curtis
02 Marvin
Table: TelephoneNumbers
Owner Number Type
---- ---- ----
01 5551515 Cell
01 5551990 Home
02 5559999 Home
In the above table, the column called ID in the table Names is the PK. The column called "Owner" in TelephoneNumbers is a FK to Names.ID. This allows me to do database look ups like "get me all telephone numbers for Curtis"; The database looks at the Names list for Curtis, finds his (my) ID, then looks for all instances of that value in the TelephoneNumbers.Owner table. Note that the above database lookup (query) is not in real SQL, the language used to look up data in a relational database.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Example of primary key and foreign key?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What does the term foreign key mean in databases?

A foreign key is a field in a database table that is used to establish a relationship with another table. It ensures referential integrity by enforcing a link between two tables based on a matching key. This key is typically a primary key in the referenced table.


Why must the primary key of a parent table be determined before the foreign key in the child table?

Because the foreign key is copied from the primary key of the parent table


Explain the concept of foreign key How a foreign key differs from a primary key?

Foreign keys are used to link one database with another. A primary key is an attribute of a record that allows users to identify information.


Can a primary key be a foreign key?

Yes, a primary key can also be a foreign key. This is known as a composite key, where one or more columns in a table are both primary keys for that table and also act as foreign keys linking to another table.


What is a primary key of one file that appears in another file?

A primary key is one that uniquely identifies a record . Also there are cases when primary key of one file appears in another file. In that case the key is called Foreign key.


Why you need primary key and foreign key?

In sql you use primary key more than one column in a table


Is it necessarily that a foreign key is primary key in other table?

It is not mandatory that is must be a primary key but it must be a unique key in the other table.


Why do you designate one of the candidate key of relation to be the primary key?

We designate one of the candidate key of a relation to be a primary key because that primary key is use for any foreign key references.


What key defines a relationship between two tables 1 Primary key 2 Secondary key 3 Foreign key?

Foreign key is used to define a relationship between two tables by referencing the primary key of another table. It ensures data integrity and enforces referential integrity between the related tables.


What ensures the value of the foreign key matches another tables primary key?

It is the DBMS that ensures the value of the foreign key matches another table's primary key when referential integrity constraints are enabled within the DBMS


What is difference between primary key and foreign key?

A primary key is an attribute (or combination of attributes) that uniquely identifies each row in a relation. A primary key is designated by underlining the attribute name. The primary key of an entity set allows us to distinguish among the various entities of the set. A foreign key is an attribute in a relation of database that serves as the primary key of another relation in the same database.


How do you apply a foreign key in a database?

The foreign key is a reference to a key (identifier) of a row in another or even the same table. When the foreign key is not null, it implies that there's an entry in the referenced table with that identifier. The syntax depends on wich database are you using, check the page in the related links below.