alter table 表 字段 numeric(10,2)

解决方案 »

  1.   

    alter table TABLE1 alter column MON numeric(10,2)
      

  2.   

    1.更改名:exec sp_rename...A.更改表名
    例:将table1改为table2
    exec sp_rename 'table1','table2'
    B.更改表中的列名
    例:将table2中的id列改为idd
    exec sp_rename 'table2.id','idd',['column']2.更改列的属性例:表table2中的列id为int型,现改为char型
    alter table table2 alter column id char3.增加列A.例:在表table2中增加name列为char型
    alter table table2 add name char(8)
    B.例:在表table2中增加nob列为int型且设自增量为1,且不空
    alter table table2 add nob int identity(1,1) not null4.删除列例:删除table2中的id列
    alter table table2 drop column id
      

  3.   

    我的数据库中有好几百个money字段啊,老大们
    我现在将系统定义的money类型的小数部分改成了2位(改的systypes表),可用户表中的money字段根本没变 ,还是4位小数,新建表也不变,重启系统还是没变
      

  4.   

    --那倒不用逐表改,可以直接用下面的语句实现--将所有的表中,数值类型由char,varchar改为nchar,nvarchar  declare tb cursor for
    SELECT sql='alter table ['+d.name
    +'] alter column ['+a.name+'] numeric(10,2))'
    FROM syscolumns a
    left join systypes b on a.xtype=b.xusertype
    inner join sysobjects d on a.id=d.id  and d.xtype='U' and  d.name<>'dtproperties'
    where 
    b.name='money'
    and 
    not exists(SELECT 1 FROM sysobjects where xtype='PK' and name in (
    SELECT name FROM sysindexes WHERE indid in(
    SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid
    ))) --主键不能修改
    order by d.name,a.namedeclare @sql varchar(1000)
    open tb
    fetch next from tb into @sql
    while @@fetch_status = 0
    begin
    exec(@sql)
    fetch next from tb into @sql
    end
    close tb
    deallocate tb
      

  5.   

    用循环搞定:
    declare @tb varchar(100),@colname varchar(100)
    while exists(SELECT d.name,a.name,b.name
    FROM syscolumns a
            left join systypes b on a.xtype=b.xusertype
            inner join sysobjects d on a.id=d.id  and d.xtype='U' and  d.name<>'dtproperties'
            left join syscomments e on a.cdefault=e.id
            left join sysproperties g on a.id=g.id and a.colid=g.smallid
    where b.name='money')
    begin
    SELECT @tb=d.name,@colname=a.name
    FROM syscolumns a
            left join systypes b on a.xtype=b.xusertype
            inner join sysobjects d on a.id=d.id  and d.xtype='U' and  d.name<>'dtproperties'
            left join syscomments e on a.cdefault=e.id
            left join sysproperties g on a.id=g.id and a.colid=g.smallid
    where b.name='money'
    exec('alter table '+@tb+' alter column '+@colname+' numeric(10,2)')
    end
      

  6.   

    to zjcxc:怎么会这样?这么说来,不是没人使用自定义数据类型了?简直不可思议,我以前还一直以为自定义数据类型是个好东西呢,原来我错了,不知道其它数据库是不是也不能修改自定义数据类型?sql server 怎么能这样呢?
      

  7.   

    我现在将系统定义的money类型的小数部分改成了2位(改的systypes表),可用户表中的money字段根本没变 ,还是4位小数,新建表也不变,重启系统还是没变
    为什么会无效呢?