34,575
社区成员
发帖
与我相关
我的任务
分享
create table tb(a int not null, b int not null, c varchar(10) not null)
go
select 执行语句 = 'ALTER TABLE tb alter column ' + a.name + ' ' + b.name + ' null'
FROM syscolumns a left join systypes b on a.xusertype=b.xusertype inner join sysobjects d on a.id=d.id and d.name='tb'
go
drop table tb
/*
执行语句
---------------------------------------
ALTER TABLE tb alter column a int null
ALTER TABLE tb alter column b int null
ALTER TABLE tb alter column c varchar null
(所影响的行数为 3 行)
*/
create table tb(id int,name varchar not null)
insert into tb values(1,'a')
alter table tb alter column name varchar(2) null
insert into tb(id) values(2)
select * from tb
drop table tb
id name
----------- ----
1 a
2 NULL
(2 行受影响)