MS Access Create Table with Autoincrement and default date

后端 未结 2 1263
日久生厌
日久生厌 2021-01-05 13:14

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.\":

CREATE          


        
2条回答
  •  再見小時候
    2021-01-05 14:13

    There are many NUMBER types in Ms-Access, so you have to be specific. I guess you want Integer.

    CREATE TABLE Table1
    (
        [ID] AUTOINCREMENT,
        [Email] TEXT(255),
        [ProductID] INTEGER,
        [DateCreate] DATETIME,
        [DateSend] DATETIME
    );
    

    The ALTER TABLE syntax requires 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:

        [ID] AUTOINCREMENT PRIMARY KEY,
    

    A page with a lot of useful information about how to handle Access with SQL:

    Intermediate Microsoft Jet SQL for Access 2000

提交回复
热议问题