怎么更新数据库的一列

来源:百度知道 编辑:UC知道 时间:2024/06/09 19:38:46
比如说原来存在一列id,表名t1,id原来是1-55,现在想升到五位的id,即原来是1的改为00001,11改为00011.
要求SQL语句
ID是char型的,不是数字。
用第二位提示错误啊 ,括号怎么回事,是什么函数?

刚才多写了个括号
update t1
set id=right(100000+cast(id as int),5)

alter table t alter column ID varchar(5) not null
go
update t
set ID=right(100000+ID,5)

什么数据库?如果是oracle:
update t1 set id=substr('0000'||id,-5);

其他数据库的,你要找到和取字串的函数替换substr;
还有字符相连的函数替代'0000'||id

update t1
set id=right('00000'+id,5)