杂七杂八!

C# .Net Sql AD Flash Javascript Ajax
(转)在SqlServer中将所有表的smalldatetime类型的字段改成datetime类型
declare @tableName varchar(50)
declare @tableID int
declare @columnName varchar(50)
declare @sql varchar(8000)

set @tableName=''
set @columnName=''

declare cur cursor for
select name,id from syscolumns
where xtype=58                                --58对应的类型是smalldatetime (参考systypes表)

open cur

fetch next from cur into @columnName,@tableID

while @@fetch_status=0
begin
    select @tableName=name from sysobjects where id=@tableID
    set @sql =' alter table '+@tableName+' alter column '+@columnName+' datetime'

print @sql

    exec(@sql)
    fetch next from cur into @columnName,@tableID
end

close cur
deallocate cur

posted on 2009-07-11 13:22  acheng  阅读(339)  评论(0编辑  收藏  举报