Search⌘ K
AI Features

Constraints and Views

Explore how to enforce data integrity using constraints such as primary keys, unique, not null, default, check, and index constraints in SQL Server. Understand views as virtual tables that combine data from multiple tables for real-time reporting without modifying original data. This lesson equips you with fundamental skills to manage and protect SQL Server data efficiently.

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 ...