将SQL Server CREATE TABLE转换为Access

时间:2016-04-30 23:08:45

标签: ms-access ddl

如何将其转换为Access create table

CREATE TABLE Employee
(
    EmployeeKey INTEGER NOT NULL IDENTITY PRIMARY KEY,
    FirstName nvarChar(25) NOT NULL,
    MiddleName nvarChar(25) NULL,
    LastName nVarChar(25) NOT NULL,
    Title nVarChar(100) null,
    ManagerKey INT NULL REFERENCES Employee(EmployeeKey),
    CreatedDate DateTime NOT NULL DEFAULT NOW(),
    UpdatedDate DateTime NULL
)

1 个答案:

答案 0 :(得分:1)

我在Access Immediate窗口中构造了这个DDL语句:

strDdl = "CREATE TABLE Employee (" & _
    "EmployeeKey IDENTITY PRIMARY KEY, " & _
    "FirstName TEXT(25) NOT NULL, " & _
    "MiddleName TEXT(25), " & _
    "LastName TEXT(25) NOT NULL, " & _
    "Title TEXT(100), " & _
    "ManagerKey LONG REFERENCES Employee(EmployeeKey), " & _
    "CreatedDate DATETIME NOT NULL DEFAULT NOW(), " & _
    "UpdatedDate DATETIME);"

由于它包含关键字DEFAULT,因此必须从ADO / OleDb执行。

CurrentProject.Connection.Execute strDdl

该声明已成功执行,如图所示。如果从DAO执行它将失败--- "运行时错误' 3292':字段定义中的语法错误。"

注意:

  • TEXT相当于NVARCHAR
  • CHAR相当于NCHAR,将导致填充字符串