Wie kann ich auf SQL-Ebene das Eintragen leerer Werte unterbinden?
Vielleicht so:
http://www.mysqltutorial.org/mysql-check-constraint/
Mögliche Lösung mit View:
CREATE TABLE Dokument ( D_Name VARCHAR(100) NOT NULL
Query OK, 0 rows affected (0,01 sec)
CREATE VIEW DokInsert AS SELECT D_Name from Dokument WHERE D_NAME > "" WITH CHECK OPTION;
Query OK, 0 rows affected (0,02 sec)
insert into Dokument set D_NAME=""; ### SO NICHT: UMGEHT CHECK ###
Query OK, 1 row affected (0,01 sec
insert into DokInsert set D_NAME="";
ERROR 1369 (HY000): CHECK OPTION failed 'test.DokInsert'
insert into DokInsert (D_NAME) values ("");
ERROR 1369 (HY000): CHECK OPTION failed 'test.DokInsert'
insert into DokInsert set D_NAME="foo";
Query OK, 1 row affected (0,01 sec)
update DokInsert set D_NAME="" where D_NAME="foo";
ERROR 1369 (HY000): CHECK OPTION failed 'test.DokInsert'
select version();
+-----------+
| version() |
+-----------+
| 5.7.20 |
+-----------+
1 row in set (0,00 sec)