Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2002
    Posts
    189

    Unanswered: Simple CREATE TABLE syntax wobble

    Hi,

    I'm trying to create a table via some godforsaken web interface-type thing that churns out this...stuff, and...

    Basically, I'm used to SQLserver, not mySQL and could somebody please tell me what the syntax error is that it keeps bleating on about in the below statement?

    CREATE TABLE forum_posts (id INT (4) UNSIGNED not null AUTO_INCREMENT, post_date DATETIME (12) DEFAULT 'NOW()' not null , user_id INT (4) not null , message TEXT (16) not null , PRIMARY KEY (id), INDEX (id), UNIQUE (id))


    Much appreciated.

  2. #2
    Join Date
    Jul 2002
    Posts
    8

    Syntax Error

    A DEFAULT value has to be a constant, it can not be a function or an expression.

    From:

    http://www.mysql.com/doc/en/CREATE_TABLE.html

  3. #3
    Join Date
    Jan 2002
    Posts
    189
    Aha. I didn't know that, thanks. So how do I make it insert the current date as a default value? Can I not do that?

  4. #4
    Join Date
    Jul 2002
    Posts
    8

    Default Date Values

    Originally posted by Spudhead
    Aha. I didn't know that, thanks. So how do I make it insert the current date as a default value? Can I not do that?
    Don't think that this is possible. MySQL doesn't have stored procedures as such so it's up to the client application to do this.

  5. #5
    Join Date
    Feb 2002
    Posts
    2,232
    Read further:

    For date and time types other than TIMESTAMP, the default is the appropriate zero value for the type. For the first TIMESTAMP column in a table, the default value is the current date and time. See section 6.2.2 Date and Time Types.

  6. #6
    Join Date
    Feb 2002
    Posts
    2,232
    So change your post_date from DATETIME to TIMESTAMP.

Posting Permissions

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