我是SQL Server的新手,所以对此有任何帮助将不胜感激。使用自动生成的记录
更新现有列时,我找不到错误这是我的表结构: -
CREATE TABLE [dbo].[EmployeeRegistration]
(
[ID] [int] NULL,
[Sr_no] [int] IDENTITY(1,1) NOT NULL,
[Branch_Code] [varchar](200) NULL,
[City] [varchar](200) NULL,
[Employee_Name] [varchar](200) NULL,
[Designation] [varchar](200) NULL,
[Department] [varchar](200) NULL,
[Date_of_Joining] [varchar](200) NULL,
[Reporting_To] [varchar](200) NULL,
[Staff_Code] [varchar](50) NULL,
[Reporting_To_1] [varchar](200) NULL,
[Staff_Code_1] [varchar](50) NULL,
[Emp_Staff_Code] AS ('T'+right('0000'+CONVERT([varchar](8),[Sr_no],(0)),(8))),
[Password] [varchar](50) NULL,
[confirmPassword] [varchar](50) NULL,
[EMAIL_id] [varchar](50) NULL,
[IsActive] [varchar](200) NULL,
[Created_By] [varchar](200) NULL,
[Created_On] [date] NOT NULL,
[Modified_By] [varchar](200) NULL,
[Modified_Date] [date] NOT NULL
)
我想使用以下查询更新Password
列: -
use AxpressDB
alter table EmployeeRegistration
alter column Password AS ('XP'+right('0123'+CONVERT([varchar](50),[Sr_no],(0)),(8)))
答案 0 :(得分:0)
列更改的语法:
ALTER TABLE tablename
ALTER COLUMN columnname columndatatype(size)
和示例:
ALTER TABLE dbo.doc_exy
ALTER COLUMN column_a DECIMAL (5, 2) ;
尝试这些方式
答案 1 :(得分:0)
您无法更改现有列并将其设为计算列,您需要删除并重新创建
alter table EmployeeRegistration
drop column Password
alter table EmployeeRegistration
add Password AS ('XP'+right('0123'+CONVERT([varchar](50),[Sr_no],(0)),(8)))