I've been trying to create a table in MS Access with PHP/Apache using ODBC.
I can create a simple table, but the problem is when I add the PRIMARY KEY attribute to the ir_no field it returns an error. :confused:
The SQL code is as follows:
When I take out the PRIMARY KEY attribute, it works fine! But as soon as I add it back, no joy. :bawling: It's enough to make you cry!
$sql = "CREATE TABLE Incident (" .
"ir_no INT PRIMARY KEY, " .
"vendor_incident_no INT, " .
"date_raised DATE NOT NULL, " .
"short_desc TEXT, " .
"review_comments TEXT, " .
"raised_by INT NOT NULL, " .
"severity INT NOT NULL, " .
"application INT NOT NULL, " .
"priority INT NOT NULL, " .
"status INT NOT NULL " .
$cur = odbc_exec( $cnx, $sql );
Also, I want the ir_no field to be auto incremented. I tried adding the AUTO_INCREMENT attribute to the ir_no field, but again it didn't like the SQL statement.
What am I doing wrong???
Thanks, and merry Christmas! :wavey:
I think you need to use this statement:
Hope that helps :)
CREATE TABLE Incident (ir_no INT AUTO_INCREMENT, vendor_incident_no INT , date_raised DATE not null , short_desc TEXT , review_comments TEXT , raised_by INT not null , severity INT not null , application INT not null , priority INT not null , status INT not null , PRIMARY KEY (ir_no))
I've tried that variation as well... Still no luck!
It returns the following error message when I include one of the AUTO_INCREMENT or PRIMARY KEY attributes (or both at the same time).
For some reason it doesen't like either one of these attributes. Very frustrating! :splat:
Warning: SQL error: [Microsoft][ODBC Microsoft Access 97 Driver] Syntax error in CREATE TABLE statement.,
SQL state 37000 in SQLExecDirect