- SQL constraints are used to specify rules for the data in a table.
- Constraints can be specified when the table is created (inside the CREATE TABLE statement) or after the table is created (inside the ALTER TABLE statement).
CREATE TABLE table_name ( column_name1 data_type(size) constraint_name, column_name2 data_type(size) constraint_name, column_name3 data_type(size) constraint_name, .... );
Types of constraints:
- NOT NULL – Indicates that a column cannot store NULL value.
- UNIQUE – Ensure that each row for a column must have a unique value.
- PRIMARY KEY – A combination of a NOT NULL and UNIQUE. Ensure that a column (or combination of two or more columns) have an unique identity which helps to find a particular record in a table more easily and quickly.
- FOREIGN KEY – Ensure the referential integrity of the data in one table to match values in another table.
- CHECK – Ensure that the value in a column meets a specific condition.
- DEFAULT – Specifies a default value when specified none for this column.
Learn how to use SQL to store, query, and manipulate data. SQL is a special-purpose programming language designed for managing data in a relational database, and is used by a huge number of apps and organizations.
We’ll show you the basics of creating tables and selecting data in various different ways.
- Lectures 41
- Quizzes 0
- Duration 50 hours
- Skill level All levels
- Language English
- Students 0
- Certificate No
- Assessments Self