SQL MS Access 创建带有自动增量和默认日期的表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6000278/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MS Access Create Table with Autoincrement and default date
提问by ihorko
I try to create MS Access Table with autoincrement ID and Default Date field, but next query always says "Syntax error in CREATE TABLE statement.":
我尝试使用自动增量 ID 和默认日期字段创建 MS Access 表,但下一个查询总是显示“CREATE TABLE 语句中的语法错误。”:
CREATE TABLE Table1
(
[ID] AUTOINCREMENT,
[Email] TEXT(255),
[ProductID] NUMBER,
[DateCreate] DATETIME,
[DateSend] DATETIME
);
ALTER TABLE Table1
ALTER [DateSend] DATETIME DEFAULT NOW() NOT NULL;
Who can help me to fix that query. Thanks!
谁能帮我解决这个查询。谢谢!
回答by ypercube??
There are many NUMBER
types in Ms-Access, so you have to be specific. I guess you want Integer
.
NUMBER
Ms-Access中有很多类型,所以你必须要具体。我猜你想Integer
。
CREATE TABLE Table1
(
[ID] AUTOINCREMENT,
[Email] TEXT(255),
[ProductID] INTEGER,
[DateCreate] DATETIME,
[DateSend] DATETIME
);
The ALTER TABLE
syntax requires ALTER COLUMN
:
该ALTER TABLE
语法要求ALTER COLUMN
:
ALTER TABLE Table1
ALTER COLUMN
[DateSend] DATETIME DEFAULT NOW() NOT NULL;
You could also have those two in one statement:
你也可以在一个语句中包含这两个:
CREATE TABLE Table1
(
[ID] AUTOINCREMENT,
[Email] TEXT(255),
[ProductID] INTEGER,
[DateCreate] DATETIME,
[DateSend] DATETIME DEFAULT NOW() NOT NULL
);
It's best practise to have a PRIMARY KEY
on every table, and you probably intended that for the ID
:
最好的做法是PRIMARY KEY
在每张桌子上都有一个,您可能打算这样做ID
:
[ID] AUTOINCREMENT PRIMARY KEY,
A page with a lot of useful information about how to handle Access with SQL:
一个页面包含许多关于如何使用 SQL 处理 Access 的有用信息:
回答by ginahlobetania
CREATE TABLE Tblcontact
(
contactid AUTOINCREMENT PRIMARY KEY ,
firstname CHAR (60),
lastname CHAR (60),
email VARCHAR (75)
);