列定义为插入时需要的自动增量

时间:2012-06-29 18:35:03

标签: ms-access oledb

我正在尝试通过SQL DDL定义MS Access表。我对传统SQL有很多经验,但访问特定语言让我陷入了困境。

CREATE TABLE DemoTable (
    Demo_id IDENTITY PRIMARY KEY,
    Demo_nm VARCHAR(200) NOT NULL
);
=> Query executed successfully. 0 rows were affected.

我已尝试AUTOINCREMENTCOUNTERIDENTITY(1,1)等。

INSERT INTO DemoTable VALUES('Some Name');
=> Number of query values and destination fields are not the same.

这是因为它需要一个Demo_id值。

INSERT INTO DemoTable VALUES(5, 'Some Name');
=> Query executed successfully. 1 rows were affected.

正确创建其他所有内容..为Demo_id创建索引,Demo_nm不可为空。

我的参考:

How to: Modify a Table's Design Using Access SQL

1 个答案:

答案 0 :(得分:1)

这对我有用:

CREATE TABLE DemoTable (
    Demo_id Counter PRIMARY KEY,
    Demo_nm VARCHAR(200) NOT NULL)

然后

INSERT INTO DemoTable (   
Demo_nm ) Values ("abc")