What is the difference between primary, unique and foreign key constraints, and indexes?

后端 未结 7 851
情深已故
情深已故 2021-01-30 11:25

What is the difference between primary, unique and foreign key constraints, and indexes?

I work on Oracle 10g<

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-30 12:04

    1. 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 column (or set of columns) in a second table whose value is required to match the value of the primary key in the original table. Usually a foreign key is in a table that is different from the table whose primary key is required to match. A table can have multiple foreign keys.
    2. The primary key cannot accept null values. Foreign keys can accept multiple.
    3. We can have only one primary key in a table. We can have more than one foreign key in a table.
    4. By default, Primary key is clustered index and data in the database table is physically organized in the sequence of clustered index. Foreign keys do not automatically create an index, clustered or non-clustered. You can manually create an index on a foreign key.

提交回复
热议问题