Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Posts
    144

    Unanswered: Copy data to auto_incremen field

    i want to divide one Table(tbl1) in 2 table(tbl1,tbl2):
    for this i use this statements:
    tbl1 have these filds:
    Code:
    CREATE TABLE `tbl1` (
      `tbl1_id` int(10) unsigned NOT NULL default '0' auto_increment,
      `tbl2_id` int(10) unsigned NOT NULL default '0',
      `tbl1_txt` varchar(100) NOT NULL default '',
      `tbl1_num` int(20) NOT NULL default 0,
       PRIMARY KEY  (`tbl1_id`)
    )
    i ADD tbl2_id to this table and fill it with this statement:
    Code:
    UPDATE `tbl1` SET `tbl2_id` = tbl1_id ;
    first create tbl2:
    Code:
    CREATE TABLE `tbl2` (
      `tbl2_id` int(10) unsigned NOT NULL default '0' auto_increment,
      `tbl2_txt` varchar(100) NOT NULL default '',
       PRIMARY KEY  (`tbl2_id`)
    )
    & then copy data from tbl1 to tbl2 in this way:
    Code:
    INSERT INTO tbl2
    (tbl2_id, tbl2_txt)
    SELECT 
    tbl1_id, tbl1_txt
    FROM 
    tbl1;
    & then DROP some feilds from tbl1.

    note that i want to make a relation bet. tbl1 & tbl2 with tbl2_id field.
    & the problem is that i cant copy tbl1_id values into the tbl2_id because of being

    auto_increment.
    this problem occur in Linux OS, i haven't this prob. in windows OS.
    Last edited by bono56; 03-01-05 at 12:36. Reason: Edit

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    What is the reason you are dividing the table in the first place?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •