nonempty constraint NOT NULL constraint:
Forcing a column to not be a NULL value, the Constraint force field always contains a value. This means that if you do not add a value to the field, you cannot insert a new record or update the record.
1. Create a not null constraint on the ID column,the name column when the "Persons" table is created:
CREATE TABLE Persons (
ID int not NULL,
P_name varchar () NOT NULL,
Deparment varchar (20),
Address varchar (20),
Telnum varchar (20)
)
DESC Persons;
Results:
Insert
Insert into Persons (id,p_name,deparment,address,telnum) VALUES (' 1 ', ' Zhang San ', ' marketing ', ' x y ', ' "') ' SELECT * from Persons
Results:
Insert a null value to see the effect:
3. Delete the NOT NULL constraint after the table is created (via the ALTER table statement):
ALTER TABLE Persons MODIFY p_name varchar (20); DESC Persons;
4. Increase the NOT NULL constraint after the table is created (via the ALTER table statement):
ALTER TABLE Persons MODIFY p_name varchar (a) not null;desc Persons;
MySQL constraint (Constraints): One, non-null constraint not a nulls constraint