what is primary key,unique key, foreign key? can u teach me
in simple language?
Answers were Sorted based on User's Feedback
Answer / teju
PRIMARY KEY :
IN THE TABLE we can find only one record as
uniqely & also it is not null.
unique key:
uk is to search any record as uniquely& when it
is declared it should be only one null values.
Fk:
fk is to maintain the relations bet two tables
as an duplicate values.means to not null.
e.g
1> stud(stud_id,stud_name);
2> stud_det(stud_id,addr);
In this table stud_id is an pk & In the stud_det as
stud_id is used as an duplicate.
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / sathish
1)Primary key is unique key but foriegn key always refers
to
primary key.
2) Primary keys enforce entity integrity by uniquely
identifying entity instances. Foreign keys enforce.
3)Primary key is unique
primary key is not NULL and
foreign key is NULL
foreign key reference as Primary key in another table.
4) primary key is used to identify a row and it doesnot
allow
null values. It avoids duplication of rows.
whereas foreign key refers to a column or combination of
columns included in the defenition of referential integrity.
referential integrity by completing an association between
two entities.
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / uma maheswari
primary key:
IT IS THE MAIN KEY AND IT DOES NOT ALLOWS THE NULL VALUE...
Unique key:
IT IS SIMILAR TO PRIMARY KEY .IT ALSO DONT ALLOWS THE NULL VALUE.
foreign key:
IT IS USED TO REPRESENT THE PRIMARY KEY VALUE...
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / vinodkumar
Primary key:it is a key in which uniquely identify the
answer which is stored in the DBMS.A table contains a
primary key.
Foreign key:A key used in the table to represent the primary
key i.e when the primary key is used in a table of one topic
then the same name can be used as foreign key in another topic
Is This Answer Correct ? | 1 Yes | 1 No |
dublicate values- means two same values not allowed
primary key:does not allow null values and does not allow
dublicate v
alues
-reapeated values and null values not allowed
-we can use primary key only once in a table
unique key:
-reapeated values not allowed as per primary key.
-but the difference is null values are allowed
-another difference is we can declare more thatn one
unique column in a table.primary is not allowed
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / mansi valani
A Foreign Key is a field in a relational table that matches
a candidate key of another table. The foreign key can be
used to cross-reference tables.
The foreign key identifies a column or set of columns in one
(referencing) table that refers to a column or set of
columns in another (referenced) table. The columns in the
referencing table must reference the columns of the primary
key or other superkey in the referenced table. The values in
one row of the referencing columns must occur in a single
row in the referenced table. Thus, a row in the referencing
table cannot contain values that don't exist in the
referenced table (except potentially NULL). This way
references can be made to link information together and it
is an essential part of database normalization. Multiple
rows in the referencing table may refer to the same row in
the referenced table. Most of the time, it reflects the one
(parent table or referenced table) to many (child table, or
referencing table) relationship.
The referencing and referenced table may be the same table,
i.e. the foreign key refers back to the same table. Such a
foreign key is known in SQL:2003 as a self-referencing or
recursive foreign key.
A table may have multiple foreign keys, and each foreign key
can have a different referenced table. Each foreign key is
enforced independently by the database system. Therefore,
cascading relationships between tables can be established
using foreign keys.
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / anbarasu
UNIQUE KEY: A Table may contain one or more UNIQUE
constraints. It’s allowing only one null value. Use this
key we maintain unique vales in the table.
FOREIGN KEY: A key used in one table to represent the value
of a primary key in a related table. While primary keys
must contain unique values, foreign keys may have
duplicates. For instance, if we use student ID as the
primary key in a Students table (each student has a unique
ID), we could use student ID as a foreign key in a Courses
table: as each student may do more than one course, the
student ID field in the Courses table (often shortened to
Courses. student ID) Will hold duplicate values.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / navya
pk-it doesn't accept null values.there must be only one pk in table.
unique-it accept null values.there may be one r more unique keys in a table.
foreign-used to refer any key
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / janu
Primary Key:
A primary key is a field or combination of fields that
uniquely identify a record in a table, so that an individual
record can be located without confusion.
Foreign Key:
A foreign key (sometimes called a referencing key) is a key
used to link two tables together.
Is This Answer Correct ? | 6 Yes | 7 No |
Answer / sandeep beniwal (master)
Primary key:- Primary key means main key. A primary key is
one which uniquely identifies of a table. Prrimay key does
not allow null values and duplicate values.
e.g:
empno empname status
10 dipender active
20 nisha inactive
30 vikas active
40 naveen active
Pimary key not like this:
10 dipender active
20 nisha inactive
30 vikas active
naveen active ........ (duplicate value)
Unique key:-A unique is one which uniquely identifies a row
of a table, but there is a difference like it will allow
only one duplicate values (In sql).
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 and helps making link
e.g
employee_table user_table
empID empname status userID userID empname
10 dipender active 1 1 dipender
20 nisha inactive 2 2 nisha
30 vikas active 3 3 vikas
40 naveen active 4 4 naveen
In the above relation, userID is there in employee_table
which
is a primary key of user_table. that means, userID is
refering the user_table.
Is This Answer Correct ? | 1 Yes | 2 No |
Is redis in memory database?
Write a query to retrieve for many to many relationships?
What is odm in database?
can anyone please tell what are the roles and responsibilities of a teradata developer in detail???
Define stored procedure?
What is database collection?
What is a database connection string?
What are the types of indexes that are present inside a database?
In TeraData We have 5 SQL queries, without using BTEQ how can we execute those queries?
What are the validations performed on the source data? If there are junk data available in the source data, how to eliminate it?
0 Answers BDI Systems, Google,
utility used to obtain inform regarding the optimizes choice of access strategy for SQL stmts A) LOAD B) REORG C) COPY D) EXPLAIN
Which is the best graph database?