If I understand you correctly, all you want is a unique document_id.
Actually that is not all I really want. For example, my table records represented web documents posted to a web site, the fields of the record include document titles and subtitles, dates the document was initially posted and modified, and perhaps even the entire contents of the document itself. I might want to compute the MD5 value of one or more of those fields, and have that automagically put into a hash value (MD5, SHA-1, CRC32...however it is calculated) field in the record during INSERT or UPDATE operations. And I might want to do a REPLACE on records already present to make sure the value is set properly, assuming I change the mode of computation for the field.
If that is so, all you need to do is create a primary key column called document_id and set it as an auto-increment integer. When you then insert values into the other columns in the table, document_id will be automatically incremented by 1.
/*Table structure for table `tbldemo` */
DROP TABLE IF EXISTS `tbldemo`;
CREATE TABLE `tbldemo` (
`fldDocument_id` int(11) NOT NULL AUTO_INCREMENT,
I am familiar that operation. What I really want the AUTO INCREMENT to do is follow a custom computation, not its x = x + 1 of an int value. Indeed, the computed "doc ID" may not even be an integer.
What is more, I don't want to have to remember the SQL myself for that field on an INSERT/UPDATE. I want it to be part of the marrow of that table when such operations are done. I am guessing that something has to be done to one of the tables in the "mysql" database to get this procedure executed....a trigger of some kind.