SQL Server - NOT NULL Constraint
What is the constraints in SQL Server?
Constraints set the rules and regulation on the columns and table to insert data.
SQL constraints keep watch on data accuracy and reliability in database .
Below image will explain the flow of transaction.
Let's start with first one.
NOT NULL constraint in SQL Server
NOT NULL constraint makes sure that NULL value should not insert into table. We can apply NOT NULL constraint on column by two way.
1) Add NOT NULL constraint on table by Query.
In below example we are creating new table of student and make the StudentName as NOT NULL constraint.
2) Add NOT NULL constraint on table using table design.
Below we are trying to insert NULL values in StudentName but StudentName columns has NOT NULL constraint.
Provide the correct data to StudentName and try to insert data once again. It show data inserted successfully.
Add NOT NULL constraint on existing columns of table.
Note : After alter existing table columns it will same reflect in table design. Check below design of table.