在SQL中,可以通过以下方式实现NOT NULL约束:
CREATE TABLE table_name (
column1 datatype NOT NULL,
column2 datatype
);
ALTER TABLE table_name
MODIFY column_name datatype NOT NULL;
CREATE INDEX index_name ON table_name (column_name) WHERE column_name IS NOT NULL;
CREATE TRIGGER trigger_name
BEFORE INSERT ON table_name
FOR EACH ROW
BEGIN
IF NEW.column_name IS NULL THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Column cannot be NULL';
END IF;
END;