hi
What is the difference between primary, unique and foreign key constraints, and indexes?
I work on Oracle 10g and Sql Server 2008
thanks in advance
hi
What is the difference between primary, unique and foreign key constraints, and indexes?
I work on Oracle 10g and Sql Server 2008
thanks in advance
Here are some reference for you:
Primary & foreign key Constraint.
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. Typically you take the primary key field from one table and insert it into the other table where it becomes a foreign key (it remains a primary key in the original table).
Index, on the other hand, is an attribute that you can apply on some columns so that the data retrieval done on those columns can be speed up.
Primary key and unique are Entity integrity constraints
Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist and no null values are entered.
Unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values. (In oracle one null is not equal to another null).
see http://stackoverflow.com/questions/707874/differences-between-index-primary-unique-fulltext-mysql
Key/index : A key is an aspect of a LOGICAL database design, an index is an aspect of a PHYSICAL database design. A key corresponds to an integrity constraint, an index is a technique of physically recording values that can be usefully applied when enforcing those constraints.
Primary/foreign : A "primary" key is a set of attributes whose values must form a combination that is unique in the entire table. There can be more than one such set (> 1 key), and the word "primary" is a remnant from the earlier days when the designer was then forced to choose one of those multiple keys as being "the most important/relevant one". The reason for this was primarily in combination with foreign keys :
Like a "primary" key, a "foreign" key is also a set of attributes. The values of these attributes must form a combination that is an existing primary key value in the referenced table. I don't know exactly how strict this rule still applies in SQL today. The terminology has remained anyway.
Unique : keyword used to indicate that an index cannot accept duplicate entries. Unique indexes are obviously an excellent means to enforce primary keys. To the extent that the word 'unique' is used in contexts of LOGICAL design, it is superfluous, sloppy, unnecessary and confusing. Keys (primary keys, that is) are unique by definition.
primary key identify uniquely every row it can not be null. it can not b duplicate.. foreign key: create relationship between two tables. can be null. can be duplicate