what is primary key,unique key, foreign key? can u teach me
in simple language?
Answers were Sorted based on User's Feedback
Answer / rajesh
Primary key - Primary key means main key
def:- A primary key is one which uniquely identifies a row
of a table. this key does not allow null values and also
does not allow duplicate values. for ex,
empno empname salary
1 firoz 35000
2 basha 34000
3 chintoo 40000
it will not the values as follows:
1 firoz 35000
1 basha 34000
chintoo 35000
Unique key - single and main key
A unique is one which uniquely identifies a row
of a table, but there is a difference like it will not
allow duplicate values and it will any number of allow
null values(In oracle).
it allows only a single null value(In sql server 2000)
Both will function in a similar way but a slight difference
will be there. So, decalaring it as a primary key is the
best one.
foreign key - a foreign key is one which will refer to a
primary key of another table
for ex,
emp_table dept_table
empno empname salary deptno deptno deptname
In the above relation, deptno is there in emp_table which
is a primary key of dept_table. that means, deptno is
refering the dept_table.
Is This Answer Correct ? | 19 Yes | 7 No |
Answer / raviraj bhardwaj
Primary key - Primary key means main key
def:- A primary key is one which uniquely identifies a row
of a table. this key does not allow null values and also
does not allow duplicate values. for ex,
empno empname salary
1 priya 35000
2 preeti 34000
3 niharika 40000
it will not the values as follows:
1 priya 35000
1 preeti 34000
niharika 35000
unique key~ unique key creates non clustered index by
default.it allows "one null value".
forigen key~
when the primary key of one table injected in other table to
make a relationship then the other key of the other table is
called foreign key.
for ex-
Dept table employs
deptno deptmame deptloc eid ename eadd deptno
in it deptno inter relate bothe the tables so that deptno
works here as a forigen kye..
Is This Answer Correct ? | 15 Yes | 4 No |
Answer / charu gautam
primary key:- the primary key of a relational table uniquely
identifies each record in the table. it can either be a
normal attribute that is guaranteed to be unique . such as
social security number in a table with no more than record
per person or it can be generated by the D B M S .such as a
globally unique identifier ,or G U I D, in microsoft SQL
server primary key may consist of a single attribute or
multiple attribute in combination.
foreign key:- A foreign key is a field (or fields) that
points to the primary key of another table.The purpose of
the foreign key is to ensure referential integrity of the
data.In other words ,only values that are supposed to appear
in the database are permitted.
Is This Answer Correct ? | 15 Yes | 5 No |
Answer / kavita ahuja
primary key is an attribute or set of attribute of a table
that uniquely identified each record whereas foreign key is
the attribute that is used to create relation between two
tables.and the values for foreign key must match with the
values of primary key to which it refers.
Is This Answer Correct ? | 21 Yes | 12 No |
Answer / rama
primary key:primary key is not allowed null values and
duplicate values.
unique key: this key allows null values but does not allow
duplicate values.
foreign key:
this key is used to refer another table.(i.e)other table
primary key values is used in foreign key table.it makes
relation ship between two tables.
Is This Answer Correct ? | 19 Yes | 10 No |
Answer / sanjeev goud
Primary key - Primary key means main key
def:- A primary key is one which uniquely identifies a row
of a table. this key does not allow null values and also
does not allow duplicate values. for ex,
empno empname salary
1 sanjeev 35000
2 rakesh 34000
3 chintoo 40000
it will not the values as follows:
1 sanjeev 35000
1 rakesh 34000
chintoo 35000
Unique key - single and main key
A unique is one which uniquely identifies a row
of a table, but there is a difference like it will not
allow duplicate values and it will any number of allow
null values(In oracle).
it allows only a single null value(In sql server 2000)
Both will function in a similar way but a slight difference
will be there. So, decalaring it as a primary key is the
best one.
foreign key - a foreign key is one which will refer to a
primary key of another table
for ex,
emp_table dept_table
empno empname salary deptno deptno deptname
In the above relation, deptno is there in emp_table which
is a primary key of dept_table. that means, deptno is
refering the dept_table.
Is This Answer Correct ? | 16 Yes | 7 No |
Answer / siya
Primary Key:- The primary key is the key which is uniquely
identifing in a table which not take null value for that
particular field and we don't take dublicate value for that
key.
Foreign Key:- Foregin Key is a key which define the primary
key into another table or any particular field of primary
key.
Is This Answer Correct ? | 14 Yes | 6 No |
Answer / prachi prakash hasabnis
A primary key (PK) is a column (s) that uniquely identifies
each row in the primary or 'parent' table. The PK not only
ensures there are no duplicate rows but it also provides a
mechanism that allows you to reference all of the
attributes (columns) of a specific row simply by referring
to one numeric value
Example: You can reference any information about a
particular customer simply by referring to that customer's
ID. The PK should be a small numeric key so that it is easy
to sort, store and search
A foreign key (FK) in related or 'child' table inherits the
primary key of the 'parent' or primary table. Thus, a PK-FK
combination establishes a relationship between the parent
and child tables
One-to-Many (1-N)
A one-to-many relationship is the most common type of
relationship
One instance of an entity (the parent) is associated with
zero or several instances of another entity (the child)
The classic example of a one-to-many relationship is that
of 'customers' and 'orders;' each customer (parent) can
have many orders, but each order (child) can be related to
only one customer
To implement this relationship, a 'customer ID' column is
added to the 'orders' table (FK) and referenced
to 'customer ID' column in the 'customers' table (PK)
Many-to-Many (N-N)
In a many-to-many relationship, many instances of one
entity are associated with many instances of another entity
The classic example of a many-to-many relationship is that
of 'orders' and 'parts'. Each order can consist of many
parts and each part can be used in many orders. This type
of relationship cannot be established directly. A third
table, called a junction table or associating table, is
used to establish the relationship. A junction table
typically has a composite PK that consists of two or more
columns that also serve as FKs. In effect you have two one-
to-many relationships linked via the junction table that
together produce a single many-to-many relationship
In the classic 'Order Entry' database example, the junction
table is referred to as the 'order detail' table; it
implements the many-to-many relationship between 'orders'
and 'parts'
The 'order detail' table contains an 'order_ ID' column
that functions as a FK and relates it to the 'orders'
table; the result is a one-to-many relationship
between 'orders' and 'order details'. The 'order detail'
table also contains a 'part_ ID' column that functions as a
FK and relates it to the 'parts' table; the result is a one-
to-many relationship between 'parts' and 'order details'.
Within the 'order detail' table, the 'order_ ID' and
the 'part_ ID' together are defined as a composite primary
key. Taken all together, the two one-to-many relationships
(orders->order_detail and parts->order_ detail) constitute
a many-to- many relationship between 'orders' and 'parts'
One-to-One (1-1)
In a one-to-one relationship, one instance of one entity is
associated with a single instance of another entity
This type of relationship is not very common. In order to
evaluate the need for a one-to-one relationship, ask
yourself why you can't just use one large table. By
implementing a one-to-one relationship you are in effect
vertically partitioning a table (splitting it into two
pieces). There are typically two reasons for vertically
partitioning a table by implementing a one-to-one
relationship: 1) security and 2) performance
Example: You split the employee table into two pieces so
that salary and other sensitive information can be stored
in separate table (security)
Example: Some columns in a large table are not accessed
frequently or contain large data types so they are moved to
a separate table (performance)
In the illustration above, the 'publishers' table is split
into two pieces; one to hold the smaller, more commonly
accessed fields and another to hold the less frequently
requested data fields that include large data types
(the 'logo' field is an image data type and the 'pr_info'
field is a text data type)
Recursive Relationship
A recursive relationship refers to a relationship
established within a table. In other words, a table
is 'related' to itself. Recursive relationships are usually
established in situations where it is useful to perform a
self-join
The classic example of a self-join is the 'employee-
manager' report. In this situation, the 'employees' table
contains name, ID and 'reports to' columns. The 'reports
to' column contains the ID (not the name) of the employee's
manager. In order to prepare a report that lists employees
and their managers by their names, a self-join is required.
In this situation, the 'reports to' column is typically
made a FK that references the PK 'employee ID' field
Is This Answer Correct ? | 9 Yes | 5 No |
Answer / haripriya
Primary Key:- The primary key is the key which is uniquely
identifing in a table which not take null value for that
particular field and we don't take dublicate value for that
key.
unique key~ unique key creates non clustered index by
default.it allows "one null value".
A foreign key (sometimes called a referencing key) is a key
used to link two tables together.
Is This Answer Correct ? | 5 Yes | 1 No |
Answer / manoj velyalan
primary key is an unique key in a table and we cant assign
null value on that.
Unique key in table it accept null value.
foreign key is the key which make a relationship between two
table.
Is This Answer Correct ? | 18 Yes | 15 No |
Explain phantom deadlock?
How heap is implemented in database?
What are the two categories of Client-Server application development?
can u combine pipeline parallelism and partition parallalism? how and whan?
a __________ is a virtual table made up of subset of actual table
What happens when shared and exclusive locks are applied on data item?
Explain the various types of normalization.
Its possible to use auto increment in oracle or not? If no means why?
What is the use of graph database?
Design an ETL process( batch job/script)from source to starting that u will not be dependent on the source in the near future?please elobarate details on what are things to consider.if you'd like to do a diagram that will be great.please answer it
Explain alternate key?
What is ole db ado?