小编典典

更改表添加列语法

sql

我正在尝试以编程方式向表Employees中添加一个身份列。不知道我的语法出了什么问题。

ALTER TABLE Employees
  ADD COLUMN EmployeeID int NOT NULL IDENTITY (1, 1)

ALTER TABLE Employees ADD CONSTRAINT
    PK_Employees PRIMARY KEY CLUSTERED 
    (
      EmployeeID
    ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, 
    ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

我究竟做错了什么?我试图导出脚本,但是SQL Mgmt Studio会进行整个Temp Table重命名。

更新 :我认为第一条带有“关键字’COLUMN’附近的语法不正确”的语句令人窒息。


阅读 172

收藏
2021-03-17

共1个答案

小编典典

只需COLUMNADD COLUMN

ALTER TABLE Employees
  ADD EmployeeID numeric NOT NULL IDENTITY (1, 1)

ALTER TABLE Employees ADD CONSTRAINT
        PK_Employees PRIMARY KEY CLUSTERED 
        (
          EmployeeID
        ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, 
        ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
2021-03-17