Saturday, 15 June 2013

Mysql clone id with trigger -


I have two tables:

  If a user does not exist (` (`Id`), Unique key 'Username' (` username ')) ENNITE = (8) tap AUTACNCRMant, username' varchar (45) null, password 'varchar (200) faucet, primary ID (`id `) MySQL default charset = latin1 AUTO_INCREMENT = 1; Make the table if the 'users_info' (`id`int (8) does not tap,` name 'varchar (35) no tap,' address' varchar (35) no primary key (`id`), engine = mice default charset = Latin1;  

I want that when a user is inserted in the table users , to automatically insert a new line in the table, users_info The same ID as the ID column in the form of a user table. When I incorporate myself, then I do them like this: include the user (username, password) values ​​('user1', 'pass1');

I believe that I should take a look at MySQL trigger I took a look but I do not know how to get key ID from the user table for every last line, which is inserted Assuming that other rows can be inserted in parallel to other threads.

If you create after INSERT trigger, You can use:

  After the user_info (item idid) value (new iid) on the users for each user, create the trigger as an 'ETInser' user; End;  

No comments:

Post a Comment