alter table 表 字段 numeric(10,2)
解决方案 »
- 不能在手动或分布事务模式下创建新的连接
- postgreql下为什么不能启动数据库LOG: database system is ready to accept connections
- 求救:MSSQL存储过程中为什么会出现将nvarchar值转换为数据类型为int的列时发生语法错误 [急]
- 如何比较同库两个表间不同,同时将某字段相同的行同步
- 奇怪!!!
- 存储过程中需要创建一个变化的表达式?请高手帮忙,在线等,解决完毕即结分
- 生成部分重复记录
- 运行Microsoft Visual Studio 2005出现问题
- 如何生成E-R图
- 急急急急……快帮忙,icevi,弱水快帮忙。
- 在企业管理器里修改数据库名称怎么做最方便?
- www.01cn.net > 阿朱(吕建伟)专区 > 阿朱原创
例:将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
我现在将系统定义的money类型的小数部分改成了2位(改的systypes表),可用户表中的money字段根本没变 ,还是4位小数,新建表也不变,重启系统还是没变
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
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
为什么会无效呢?