22,209
社区成员
发帖
与我相关
我的任务
分享
ALTER TABLE t_subprocessplan alter column processnumber SMALLIT
ALTER TABLE t_subprocessplan alter column processnumber smallint
--建议将这列的数据先备份一下,然后再转换类型。
ALTER TABLE t_subprocessplan alter column processnumber SMALLIT
ALTER TABLE t_subprocessplan alter column processnumber SMALLIT
求一SQL语句修改类型为text的列到char(255)!
----------------------
--2005.
create table tb(a text)
insert into tb values ('aaaaaa')
go
alter table tb alter column a char(255)
go
select * from tb
drop table tb
/*
a
------------
aaaaaa
(1 行受影响)
*/
-----------------------
--2000
create table tb(a text)
insert into tb values ('aaaaaa')
go
--加个列B
alter table tb add b char(255)
go
--将B设置为A的值
update tb set b = cast(a as varchar)
go
--删除A
alter table tb drop column a
go
--更改列名B为A
EXEC sp_rename 'tb.[b]', 'a', 'COLUMN'
go
select * from tb
drop table tb
/*
a
---------------------
aaaaaa
(所影响的行数为 1 行)
*/