--- Wade Smart <[EMAIL PROTECTED]> wrote:

> I've got myself stuck and Im probably over thinking this.
> 
> I have a registration table and a player table (sports related).
> When a player registers for the first time I need to first put them in the 
> player table, get their player_id and then put other data including the 
> player_id in the registration table. One action must come before the other.
> The guy Im working with says Im needing trigger functions but, is there no 
> way without taking another extra step of having the user first fill our a 
> new player  card and then registering?
> 
> wade

You can do this with two queries.  To fake it since I don't know your table
names or structure:

INSERT INTO players SET fname='Bill', lname='Smith', join=NOW();
INSERT INTO registration SET uid=LAST_INSERT_ID, team='Reds', updated=NOW();

What I'm trying to illustrate here is that the second query uses LAST_INSERT_ID
to hold the primary key value from the players table.  More details on this in
the MySQL docs:

http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html

Triggers are useful for other purposes but they'd be overkill here.

http://dev.mysql.com/doc/refman/5.0/en/using-triggers.html

Perhaps your friend is used to MS SQL or Oracle?

James


Reply via email to