将某表的所有列设置成允许为空!写了一个触发器,生成一张表表是这样生成的Select t.* Into tCutDSize_del From  (Select Top 0 * From tCutDSize) t;这样生成,所有的约束,什么主键都不会有,但是tCutDSize 表中的一些不允许为空的 属性 给带到生成的表tCutDSize_del中来了!有没有什么方法 可以把 tCutDSize_del表中的所有字段设置成允许为空!要代码实现!

解决方案 »

  1.   

    要对这个表的每一列进行alter操作
    alter table tCutDSize_del alter col 类型 null
      

  2.   

    create table tb(id int identity(1,1) not null,col nvarchar(100) not null)
    insert into tb select 'abcd'
    go
    select * into tb1 from (select max(id)id,max(col)col from tb where 1=0 group by id,col)t
    --所建tb1的两列无 not null 约束.
    go
    drop table tb
      

  3.   

    这样就用不着你写列名了:
    drop table tb1
    go
    create table tb(id int identity(1,1) not null,
    col1 nvarchar(100) not null,
    col2 nvarchar(100) not null,
    col3 nvarchar(100) not null,
    col4 nvarchar(100) not null,
    col5 nvarchar(100) not null,
    col6 nvarchar(100) not null,
    col7 nvarchar(100) not null,
    col8 nvarchar(100) not null,
    col9 nvarchar(100) not null,
    col10 nvarchar(100) not null
    )
    insert into tb select 'a','b','c','d','e','f','g','h','i','j'
    go
    declare @s nvarchar(4000),@s1 nvarchar(4000)
    select @s=isnull(@s+',max(','')+a.name+')'+a.name,@s1=isnull(@s1+',','')+a.name from syscolumns a inner join sysobjects b on a.id=b.id where b.type='u' and b.name='tb'
    exec ('select max('+@s+' into tb1 from tb where 1=0 group by '+@s1)
    go
    drop table tb
      

  4.   

    --没试过
    Select * Into tCutDSize_del From tCutDSize where 1=2