How do I create a table alias in MySQL

后端 未结 7 770
忘了有多久
忘了有多久 2020-12-05 23:08

I am migrating an MS Access application (which has linked tables to a MSSQL Server) to MySQL.

As a means to overcome some MSAccess table naming problems, I am seeki

相关标签:
7条回答
  • 2020-12-05 23:57

    You can create a View.

    CREATE VIEW dbo_customers AS SELECT * FROM customers;
    

    If that doesn't work for you, you could try creating a shadow-copy of the table, and use Triggers to keep the tables synced.

    For example:

    CREATE TABLE t1( id serial primary key, field varchar(255) not null );
    CREATE TABLE dbo_t1( id serial primary key, field varchar(255) not null );
    
    -- INSERT trigger
    CREATE TRIGGER t1_dbo_insert AFTER INSERT ON t1
    FOR EACH ROW BEGIN
        INSERT INTO dbo_t1 SET field = NEW.field;
        -- No need to specify the ID, it should stay in-sync
    END
    
    -- UPDATE trigger
    CREATE TRIGGER t1_dbo_update AFTER UPDATE ON t1
    FOR EACH ROW BEGIN
        UPDATE dbo_t1 SET field = NEW.field WHERE id = NEW.id;
    END
    
    -- DELETE trigger
    CREATE TRIGGER t1_dbo_delete AFTER DELETE ON t1
    FOR EACH ROW BEGIN
        DELETE FROM dbo_t1 WHERE id = OLD.id;
    END
    

    Not exactly an 'alias', and far from perfect. But it is an option if all else fails.

    0 讨论(0)
提交回复
热议问题