Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 How to create table with an AUTOINCREMENT field

Author  Topic 

lianbo
Starting Member

1 Post

Posted - 2002-05-21 : 16:57:42
Hi All,

I want to create an Access table using SQL command.
The table include an AUTOINCREMENT field and a field with foreign key.

These two fields' datatype is Long, but I don't know how to define AUTOINCREMENT and a foreign key.

My SQL like:

strSql="Create table " & tab_name &_
"(" &_
"msgId Long AUTOINCREMENT Primary Key Not Null, " &_
"parentId Long Foreign Key Not Null, " &_
")"

Set adoConn = Server.CreateObject("ADODB.Connection")
adoConn.Open "Driver={Microsoft Access Driver (*.mdb)};" &_
"dbq=" & Server.MapPath("MyDB.mdb")

set adoRs = adoConn.execute(strSql)

It runs error. Can anyone know how to make the SQL command?

Thanks in advanced

Lianbo


rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2002-05-21 : 20:06:53
Create table tempTable (parentId autoincrement Primary Key)

works for me - get rid of LONG -

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page
   

- Advertisement -