mysql client - select * minus a set of columns
When using the mysql client, I'm working on some tables that have like 10 columns plus 4 columns of meta information (created_at,created_at_utc, update_at, updated_at_utc - similar to rails). I'm trying t开发者_运维问答o create a way to essentially do a select * minus these 4 sets of columns mostly to make it so that it fits in a single window without breaking the results. I'm leaning towards writing a stored procedure / program with the table name but wondering if there is a better way. something like:
>call t($table_name)
Might there be a better way to do this? thx
edit: so I'm not concerned about performance, I would use this only to verify things are being updated / inserted correctly.
if it is select only, then you can make a view...
There is no built-in way to achieve this.
You do better not to use *
at all. This will slow down the query optimizer.
There are two simple solutions that allow for the non-meta columns to grow without code modification or maintaining a view:
Documented naming convention: Prefix them all with say,
meta_
and do not display those columns. Downside: they are requested and part of the result set, hence more overhead.Split meta columns into a separate table using 1:1 relationship and create a view for other applications / application paths to use. Downside: some overhead on each query for the 1:1 join.
精彩评论