SQL - SPLessons

SQL Certification Not Null Constraint

Chapter 25

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

SQL Certification Not Null Constraint


shape Description

SQL Databases are huge gathering of logical related information which can be created, accessed, managed, and updated. The data can be in any form like text and numbers. And by defining a column with Not NULL constraint then that constraint column won’t acknowledge null values. The constraint NOT NULL implements a field to dependably contain a quality. This implies that another record cannot be embedded, or overhaul a record without increasing the value of this field.

shape Syntax

create table<table_name>(<column_name1>datatype(size)constraint constraint name constraint_type, <column_name2>datatype(size));
Table_name => Any accurate table.

Column_name =>The operation that can be perform on a column in the table.

constraint_type =>constraint type will specify the type of constraint, that is going to be executed in the database.

shape Examples

By viewing the below example, the concept of not null constraint can be easily understood.

sql> create table stud12(stu_id number(4)constraint Stud12_stu_id_nn not null,stu_name varchar(255)not null,fee (7,2));
Query OK, 0 rows affected (0.41 sec)

sql>insert into stud12 values(1001,'jack',12000);
Query OK, 1 row affected (0.10 sec)

sql> insert into stud12 values(null,'jack',12000);
ERROR 1048 (23000): Column 'stu_id' cannot be null

In the above example if not null constraint is applied on a column_name emp_id, then that column will accept the values other than null values.


shape Key Points

  • NULL Constraint – Will not accept Null values.