Exploring Types of Constraints

Now, you'll study the different types of constraints that can be created on database tables. Following is a list of those constraints:

  • NOT NULL

  • Primary key

  • Unique

  • Foreign key

  • Check

Each of these constraints have their own function. The functions and syntax of each of these constraints are discussed in the following subsections, as well as their place in a relational database.

NOT NULL Constraints

When you initially create a table, you must assign a data type to each column in the table. The data type assigned to a column tells the database what kind of data can be inserted into that column in a table. The different types of data mainly include Character data, Numeric data, and Date and Time data.

A basic CREATE TABLE ...

Get Sams Teach Yourself SQL in 21 Days, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.