Constraints and Views
Learn about the database components like constraints and views.
Constraints
Primary and foreign keys are known as constraints in the database. Constraints are rules set in place regarding the types of data that we can enter. Several others are used aside from primary and foreign keys that help maintain the integrity of the data.
The ADD CONSTRAINT
command is used to add the constraint when we have already created a table.
Use the DROP CONSTRAINT
command to drop a constraint from the table.
The UNIQUE constraint
The UNIQUE
constraint enforces all values in that column to be different. We can apply this example to the “Product” table. Each product should be different since we wouldn’t want to store the same product name multiple times. We can see the UNIQUE
constraint is applied on “ProductName” in the table below.
Get hands-on with 1400+ tech skills courses.