SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: MySql question

  1. #1
    SitePoint Enthusiast Guni's Avatar
    Join Date
    Jun 2001
    Location
    London (mostly)
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySql question

    Hi guys,

    I hope this comes accross:
    I need to set up a MySql database which will then be exported to a text file. In the text file I need values such as B000000, ie B and 6 digits whereby the numbers are created with auto_increment as used for an id column.

    So the result should look like this:
    B000001
    B000002
    .
    .
    .
    B000255
    etc


    Is there a way of doing this?

    Thank you,

    Guni

  2. #2
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Auto_Increment columns are numeric only.

    When you do your dump do you have the ability to dump a specific query? Or a table?

    You could create a special table which uses a VARCHAR field and then you do something like this:
    SELECT 'B' + auto_increment_column, ...
    FROM old_table
    INTO new_table

    dump new_table

  3. #3
    SitePoint Enthusiast Guni's Avatar
    Join Date
    Jun 2001
    Location
    London (mostly)
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Matt,

    I thought about this and creating a new table would for sure work. The problem though are the required 6 digits, or can you set an auto_increment numneric column to have a default layout of 6 digits, ie 000000?

    Guni

  4. #4
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use this as the definition: INT(6) ZEROFILL.
    ck :: bringing chris to the masses.

  5. #5
    SitePoint Enthusiast Guni's Avatar
    Join Date
    Jun 2001
    Location
    London (mostly)
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great! Thank you, everything is working fine.


Bookmarks

Posting Permissions

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