From the course: Introduction to SQLite

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Setting rules on your data

Setting rules on your data - SQLite Tutorial

From the course: Introduction to SQLite

Setting rules on your data

- [Instructor] Your data can get messy quickly if there are no rules to govern what can be added to a table. Let's look at some ways that you can avoid this type of mess. When you create a table, you can declare a number of constraints, which allow you to restrict what kinds of data can be inserted. You've got primary key constraints, unique constraints and check and not null constraints. I'll start with the unique constraint first. The unique constraint enforces a rule that a given value may appear only once in the column that it is applied to. If you try to insert a row containing a duplicate value for that column, it will raise an error. Here, I'll try to insert two rows with an ID of 100 and I get a unique constraint failed error because of that. The primary key constraint is similar. We'll dive into that in the next video along with a foreign key constraint. You can insert any number of nulls into a unique column.…

Contents