MySql - Can I add a label to a table and retrieve using sql query

Vijayakumar Chava :

I have a requirement to provide a REST endpoint to create/delete tables for a privileged user.

When user makes a request to create table 'xyz', I create table with prefix "user_" and return response saying 'user_xyz' is created. This way I know what tables are candidates for deletion when a request is made.

But I wish to create table "xyz" as requested by user and would like to add some label like "deletable" so that I can query to find if a table can be deleted.

One option is adding a comment for table and but I have to query information_schema. Comment does not sound very correct. Can this problem be solved using any other approach when I use MySql database.

Nae :

I don't think you have much other options other than the one you suggest,

  • prefixing/suffixing table name
  • use table comment
  • create meta table with UserId(has the advantage of foreign keys) and TableName fields (has the disadvantage of integrating the table name with the actual very table as it can change without this metatable being updated)
  • create separate schema for each user

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=5669&siteId=1