By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE mytable (
id int AUTO_INCREMENT NOT NULL,
title varchar(80),
owner varchar(30) default substring_index(user(), '@', 1), -- record owner
constraint sameuser check (owner = substring_index(user(), '@', 1)),
PRIMARY KEY (id)
);
INSERT INTO `mytable` VALUES (1,'created by root'),(4,'created by helen'),(6,'created by helen1'),(7,'123');
Function or expression 'user()' cannot be used in the CHECK clause of `sameuser`
INSERT INTO `mytable` VALUES (1,'created by root'),(4,'created by helen'),(6,'created by helen1'),(7,'123');
Table 'db_844849085.mytable' doesn't exist
select * from mytable
Table 'db_844849085.mytable' doesn't exist
INSERT INTO `mytable` VALUES (1,'created by root', 'somebodyelse'),
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
select user()
user() |
---|
u_844849085@localhost |