Is it possible to have a non-null column where the value is generated at insert by calling a stored procedure the parameters of which are values passed to insert into the row?
For example, I have table User
:
| username | name | surname | id |
Insert looks like this:
INSERT INTO USER (username, name, surname)
VALUES ('myusername', 'myname', 'mysurname');
The id
column is populated with an (integer) value retrieved by calling stored procedure mystoredproc
with parameters myusername
, myname
, mysurname
.
A further question is, would this stored procedure be called on each row, or can it be called in a grouped fashion. For example, I'd like my stored procedure to take the name
and append a random integer to it so that that if I insert 100 users with the name 'David', they will get the same id
and the stored procedure will be called only once. A bit of a bad example on the second point.