0

I have a QSqlDatabase of QSQLITE type which give me this error

near "AUTO_INCREMENT": syntax error Unable to execute statement

on this statement (which MySQL executes correctly)

CREATE TABLE `Student` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`fullname` TEXT NOT NULL ,
`date_of_birth` TIMESTAMP NOT NULL ,
`date_enrolled` TIMESTAMP NOT NULL ,
`current_academic_year` INT NOT NULL
)

I tried changing AUTO_INCREMENT to AUTOINCREMENT and then to id NOT NULL INTEGER PRIMARY KEYbut neither made any difference.

What's wrong with it?

spraff
  • 32,570
  • 22
  • 121
  • 229

1 Answers1

0

The correct syntax is:

CREATE TABLE `Student` (
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
"fullname" TEXT NOT NULL ,
"date_of_birth" DATETIME NOT NULL ,
"date_enrolled" DATETIME NOT NULL ,
"current_academic_year" INTEGER NOT NULL
)
Nejat
  • 31,784
  • 12
  • 106
  • 138
  • Thanks. For extra credit, is there a good place where the language differences (*specifically* when compared to MySQL) are documented? – spraff Apr 06 '14 at 15:32
  • I don't know a good document that highlights the differences. But you can see this post: http://stackoverflow.com/questions/751160/mysql-and-sqlite-differences-in-sql – Nejat Apr 06 '14 at 15:40