Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create table with Autonumber field in MS - Access at run time?

Tags:

ddl

ms-access

I am working with MS-Access and JSP. I want to know that how can we create table with autonumber field and with primary key.

query="Create Table Registration_A (Reg_No PRIMARY KEY AUTOINCREMENT, FName varchar(2))";

But its giving syntax error. What's the correct syntax?

like image 598
samiksha Avatar asked Aug 17 '11 12:08

samiksha


2 Answers

CREATE TABLE Registration_A (
Reg_No AUTOINCREMENT, 
FName VARCHAR(2), 
CONSTRAINT RegA_PK PRIMARY KEY(Reg_No))
like image 65
Jacob Avatar answered Oct 13 '22 12:10

Jacob


You can use the COUNTER keyword to create an AutoNumber field using DDL. I just tested this in a Java console app and it worked for me under both the JDBC-ODBC Bridge and UCanAccess:

String query = 
        "CREATE TABLE Registration_A (" +
            "Reg_No COUNTER PRIMARY KEY, " +
            "FName VARCHAR(2))";
Statement stmt = con.createStatement();
stmt.executeUpdate(query);
like image 45
Gord Thompson Avatar answered Oct 13 '22 13:10

Gord Thompson