Primary keys, Foreign keys, and Integrity constraints
Primary Keys A primary key is a unique, non-nullable column that specifies a single record in a table. This means that no two records can have the same prim...
Primary Keys A primary key is a unique, non-nullable column that specifies a single record in a table. This means that no two records can have the same prim...
Primary Keys
A primary key is a unique, non-nullable column that specifies a single record in a table. This means that no two records can have the same primary key value, ensuring data integrity and consistency.
Foreign Keys
A foreign key is a column that references a primary key column in another table. This means that data in the foreign key column can be linked to data in the primary key column. Changes made to the primary key column will automatically update the foreign key column, ensuring that the data is consistent across the two tables.
Integrity Constraints
An integrity constraint is a rule that enforces specific constraints on data, such as ensuring that a value in one column is always greater than or equal to a value in another column. These constraints help to maintain the integrity and consistency of data, ensuring that data is accurate and reliable.
Examples:
Primary Key:
A table named Students with a column named student_id that is a primary key.
This means that no two students can have the same student ID.
Foreign Key:
A table named Orders with a column named customer_id that references the student_id column in the Students table.
This means that each order must be placed by a valid student.
Integrity Constraint:
A table named Courses with a column named semester that must be greater than or equal to 1 and less than or equal to 12.
This constraint ensures that the semester column contains valid values