1 Answers
Primary Key vs Unique Key in DB2
Primary Key and Unique Key are both used in DB2 to enforce data integrity and ensure uniqueness of values in a table. The main differences between them are:
- Primary Key:
- There can be only one Primary Key defined per table in DB2.
- Primary Key does not allow NULL values.
- Primary Key automatically creates a unique index on the specified column(s).
- Can be referenced by foreign keys from other tables.
- Unique Key:
- Multiple Unique Key constraints can be defined per table in DB2.
- Unique Key allows NULL values, but only one NULL value is allowed (except in columns defined as NOT NULL).
- Unique Key also creates a unique index on the specified column(s).
- Unique Key values do not have to be used in foreign key relationships.
It is important to choose between Primary Key and Unique Key based on the specific requirements of your database schema to ensure data consistency and integrity.
Please login or Register to submit your answer