mysql - global disable update of primary key column -


is possible disable possibility update primary key column on global level via global session or server variable?

or need manually check update trigger in each table?

no. it's not possible prohibit update column part of "primary key" constraint, using global, server, session, et al. variable.

if want prevent update statement making change, try enforcing before update trigger on each table.

set new.primary_key_col = old.primary_key_col; 

followup:

dmjm says: "i rather throw error ..."

to throw error trigger using mysql 5.5 or later, can use new signal syntax. http://dev.mysql.com/doc/refman/5.5/en/signal.html

with mysql 5.1 or earlier, there's no direct way throw error, developers implemented "bad" code executed (virtually) guarantee error thrown.

if ( new.primary_key_col <> old.primary_key_col )   update `error: primary_key_col modification not allowed` set dummy=0 dummy=-1; end if; 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -