• Programming 25.07.2009

    I recently tried creating a new database table only to learn a table with that name exists already.

    [me@mysql db] > CREATE TABLE log_search (
    log_search_id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL
    , search VARCHAR(255)
    , created_by VARCHAR(128), created_on DATETIME)
     ENGINE=InnoDB CHARSET=utf8;
    ERROR 1050 (42S01): Table 'log_search' already exists
    [me@mysql db] > DESC log_search;
    +---------------+---------------------+------+-----+---------------------+----------------+
    | Field         | Type                | Null | Key | Default             | Extra          |
    +---------------+---------------------+------+-----+---------------------+----------------+
    | log_search_id | bigint(20) unsigned |      | PRI | NULL                | auto_increment |
    | search        | varchar(255)        |      |     |                     |                |
    | created_on    | datetime            |      |     | 0000-00-00 00:00:00 |                |
    | created_by    | varchar(128)        |      |     |                     |                |
    +---------------+---------------------+------+-----+---------------------+----------------+
    4 rows in set (0.00 sec)

    I love naming conventions!  My favorite part of programming is when I start to write a routine only to learn I already wrote it months ago in preparation for what I knew I’d be doing now.

    Posted by Ben @ 7:45 am

  • 2 Responses

    WP_Modern_Notepad
    • just pixels Says:

      I tried to create that same table back in 1975, but E.F. Codd beat me to it.

      Just in passing, does mySQL support default column values? Like “created_on default now”.

    • just pixels Says:

      why does your table need a unique ID? There is (presumably) no update, just insert and done. Does MySQL require PKs?

    Leave a Comment

    Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.