Not Null in DBMS
NOT NULL
On this page we will discuss about NOT NULL in DBMS. Once not null is applied to a particular column, you cannot enter null values to that column and restricted to maintain only some proper value other than null It is an important concept of DBMS.So, lets just discuss it in detail.NOT NULL IN DBMS
Null
value is different from zero value or a field that contain spaces- Null represents a record where data may be missing data or data for that record may be optional
- Not all constraints prevents a column to contain null values
- Once not null is applied to a particular column, you cannot enter null values to that column and restricted to maintain only some proper value other than null
- A not-null constraint cannot be applied at table level
Syntax
CREATE TABLE table_name
(
column1 datatype(size),
column2 datatype(size),
column3 datatype(size) NOT NULL ,
);
Example
CREATE TABLE STUDENT
(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR (25) ,
SALARY DECIMAL (18, 2),
PRIMARY KEY (ID)
);
- In the above example, we have applied not null on three columns ID, name and age which means whenever a record is entered using insert statement all three columns should contain a value other than null
- We have two other columns address and salary, where not null is not applied which means that you can leave the row as empty or use null value while inserting the record into the table
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment