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:


  • 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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.