Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2010
    Posts
    2

    Unanswered: What's wrong with this code?

    Code:
    CREATE TABLE Artikel (
      Artikel_ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
      Ausgabe_ID INTEGER UNSIGNED NOT NULL,
      Dok_Nr INTEGER UNSIGNED NULL,
      Titel VARCHAR(200) NULL,
      Inhalt TEXT NULL,
      Anfangsseite INTEGER UNSIGNED NULL,
      Endseite INTEGER UNSIGNED NULL,
      Erfassungsdatum DATE NULL,
      Korrekturdatum DATE NULL,
      CONSTRAINT pk_artikel PRIMARY KEY (Artikel_ID)
    );
    FEHLER: Fehler »syntax error« bei »UNSIGNED«
    LINE 2: Artikel_ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    ^

    ********** Fehler **********


    SQL Status:42601
    Zeichen:45



    I'm new to sql and I'd be thankful if you could help me!

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    auto_increment and unsigned are not valid for PostgreSQL.

    You want
    Code:
    artikel_id serial not null
    For more details please check the manual

    http://www.postgresql.org/docs/current/static/datatype.html

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by flhe View Post
    What's wrong with this code?
    when you run it against MySQL, nothing
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Aug 2009
    Location
    Olympia, WA
    Posts
    337
    Try:
    Code:
    CREATE TABLE Artikel (
      Artikel_ID SERIAL NOT NULL,
      Ausgabe_ID INTEGER NOT NULL,
      Dok_Nr INTEGER,
      Titel VARCHAR(200),
      Inhalt TEXT,
      Anfangsseite INTEGER,
      Endseite INTEGER,
      Erfassungsdatum DATE,
      Korrekturdatum DATE,
      CONSTRAINT pk_artikel PRIMARY KEY (Artikel_ID)
    );

  5. #5
    Join Date
    Jan 2010
    Posts
    2
    Thanks guys, didn't know postgresql and mysql where that different in syntax. I'm a newb you see

    But what about the foreign key "Ausgabe_ID", doesn't it have to be SERIAL to or will this be defined in the Ausgabe table?

    Code:
    CREATE TABLE Artikel (
      Artikel_ID SERIAL NOT NULL,
      Ausgabe_ID INTEGER NOT NULL,
      Dok_Nr INTEGER,
      Titel VARCHAR(200),
      Inhalt TEXT,
      Anfangsseite INTEGER,
      Endseite INTEGER,
      Erfassungsdatum DATE,
      Korrekturdatum DATE,
      CONSTRAINT pk_artikel PRIMARY KEY (Artikel_ID)
    );

  6. #6
    Join Date
    Jan 2010
    Posts
    4
    The data types serial is not a true type, but merely a notational convenience for creating unique identifier columns (similar to the AUTO_INCREMENT property supported by some other databases). In the current implementation, specifying:

    If you created Ausgabe_Id SERIAL in another table, as a primary key, then it is ok to give it the data type of INTEGER in this table.

    Hint: a quicker way to assign primary keys to your SERIAL fields is as follows:

    Code:
     
    CREATE TABLE Artikel (
      Artikel_ID SERIAL PRIMARY KEY,
      Ausgabe_ID INTEGER NOT NULL,
      Dok_Nr INTEGER,
      Titel VARCHAR(200),
      Inhalt TEXT,
      Anfangsseite INTEGER,
      Endseite INTEGER,
      Erfassungsdatum DATE,
      Korrekturdatum DATE
    );
    Since you assigned the type SERIAL it will never be NOT NULL. Postgres will generate a primary key name for you. Just a suggestion.

    You should read the postgres manual. It was very helpful for me.

    PostgreSQL: Manuals

Posting Permissions

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