Constraints tell the database how to check the correctness of input data. Get to know the constraints available in SQL Server, MySQL, Oracle, and PostgreSQL. Learn how to create and alter constraints in a relational database.
Ultimate money saver
With our Forever plan this course will cost you only
39 hours left
Welcome to SQL Constraints! This is the third course in the track Creating Database Structure. We assume that you know the basic syntax of how to create a table in SQL. You should also know the data types available in a SQL database.
In this course, we talk about database constraints. A constraint is a mechanism that relational databases use to check data correctness. They can verify if a value is unique or is a certain type of data. You can also use constraints to make sure important fields are not left empty.
SQL databases have several types of constraints: primary keys, foreign keys, UNIQUE, NOT NULL, CHECK, and DEFAULT. We will show you how to create tables with constraints and how to drop or modify a constraint.
This interactive tutorial is based on standard SQL; what you learn here will work in all popular relational database management systems, including SQL Server, MySQL, Oracle, and PostgreSQL.
This is a course for beginning IT professionals, computer science students, programmers, developers, and junior database administrators (DBAs). If you need to learn about controlling data entered into a relational database, this is the course for you.
The topics discussed in this course are:
This course is interactive. You solve the exercises directly in your web browser and learn how different constraints work. You’ll be writing real SQL commands, which our online platform runs and verifies. You don’t need to install anything on your computer.
What are database constraints? A short recap of primary keys and foreign keys.
Updating and deleting with foreign keys
Learn how you can make sure that all values in a column are different.
Defining columns with UNIQUE
Adding and removing UNIQUE constraints
Learn how to make sure that a column in a database has a value.
Price below zero? Customer over 200 years old? Learn how CHECK constraints can ensure that information in a database is correct.
CHECK constraints with a simple condition
CHECK constraints with complex conditions
Adding CHECK constraints to existing tables
How to provide a default value for a column.
Defining columns with DEFAULT
Adding DEFAULT to existing tables