NOT NULL constraint in sql server


NOT NULL- This constraint is responsible for a column to confirm that a column cannot have a null value.

Example-

Following we create new table PRODUCT and add six columns where ID, SKU, TITLE, PRICE specify not to accept NULLs.


CREATE TABLE PRODUCT
(
  ID INT NOT NULL,
  SKU VARCHAR(20) NOT NULL,
  TITLE VARCHAR(200) NOT NULL,
  PRICE MONEY NOT NULL,
  DESCRIPTION VARCHAR(2000)  NULL,
  DTCREATE DATETIME NULL
)


If PRODUCT table already created, then to add a NOT NULL constraint to the SKU column, we use the following query.


ALTER TABLE PRODUCT ALTER COLUMN SKU  VARCHAR (20) NOT NULL

Related Posts

What is the Use of isNaN Function in JavaScript? A Comprehensive Explanation for Effective Input Validation

In the world of JavaScript, input validation is a critical aspect of ensuring that user-provided data is processed correctly. One indispensa...