database design - MySQL constants table -
how can create constants table in mysql match type (using int differentiate among different types) full name of type. constants table should read , not expected ever need changing or updating reading.
create table accounts ( accounttype int, ... ); create table accounttypes ( typeid int, typename varchar(255), );
in java there immutablemap<integer><string>
(in guava), or enums integer instance variables, , in c++ there enum or static const string[...] ... = { ... }
type integer index.
is possible, or there better alternative?
looks need similar this:
create table accounttype ( typeid int primary key, typename varchar(255), typeshortname varchar(255) ); insert accounttype values (1, 'foo', 'f'), (2, 'bar', 'br'), (3, 'baz', 'bz'); create trigger accounttypeinserttrigger before insert on accounttype each row signal sqlstate '45000' set message_text = 'cannot insert - accounttype table read-only.'; create trigger accounttypeupdatetrigger before update on accounttype each row signal sqlstate '45000' set message_text = 'cannot update - accounttype table read-only.'; create trigger accounttypedeletetrigger before delete on accounttype each row signal sqlstate '45000' set message_text = 'cannot delete - accounttype table read-only.';
essentially, define normal table , fill data, then use triggers forbid changes.
according mysql documentation: to signal generic sqlstate value, use '45000', means “unhandled user-defined exception.”
alternatively, revoke privileges except select appropriate users.
Comments
Post a Comment