SQL Constraints - Not null Key Constraint - DotNet and DataBase

Wednesday, 1 August 2018

SQL Constraints - Not null Key Constraint



The Not Null Key constraint is to restrict the null values enter in a column. By default, table columns allow null values. To stop null values to be entered, we need to use the Not Null Key constraint.
Not Null Key constraint keeps column null value free.

Example:

CREATE TABLE Employees (
    ID int NOT NULL Primary Key,
    LastName varchar(255) NOT NULL UNIQUE,
    FirstName varchar(255),
    Age int
);


So, from the above script, the user doesn't allow to enter null values on LastName column.

Using Alter command:
Syntax:

ALTER TABLE [Table] ALTER COLUMN [Column] INTEGER NOT NULL;
Example:
ALTER TABLE Employees ALTER COLUMN FirstName varchar(255) NOT NULL;

No comments:

Post a Comment

x

Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.