Yes, you will have to grab the userid and insert it into student table,
Mysql has no concept of dependent keys (in 3.23.xx).
You can write a perl or php application to do that.

Regards,
Bhavin.
----- Original Message -----
From: "Joćo Borsoi" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, November 02, 2002 3:09 PM
Subject: auto_increment in multiple tables...


>
> Hello list,
>
> I have two tables, USER and STUDENT, where all students are users. The
> user table has an auto-increment key field. I want to make an operation
> to insert users, which should insert rows in both tables (see the tables
> bellow).
>
> How can I control the auto_increment field in both tables? Do I have to
> insert a user, make a query to get its userId and then finally insert
> into the student table? Isn't there a better way of doing this??
>
>
>
> Here are the tables:
>
> CREATE TABLE USER (
> userId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
> login VARCHAR(80) NOT NULL,
> password VARCHAR(15) NOT NULL,
> status CHAR(1) NOT NULL,
> regDate DATETIME NOT NULL,
> UNIQUE (login)) TYPE = InnoDB;
>
> CREATE TABLE STUDENT (
> userId INTEGER UNSIGNED NOT NULL PRIMARY KEY,
> cardsPendingCorrection INTEGER UNSIGNED NOT NULL,
> cardsOK INTEGER UNSIGNED NOT NULL,
> cardsNotValid INTEGER UNSIGNED NOT NULL,
> cardsCorrected INTEGER UNSIGNED NOT NULL,
> cardsCommented INTEGER UNSIGNED NOT NULL,
> pendingExercices CHAR(1) NOT NULL,
> teacher INTEGER UNSIGNED NOT NULL,
> INDEX (teacher));
>
>
> Thanks,
> Joao.
>
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to