sql 全部数据表中 插入字段

declare @tablename varchar(200)
declare @sql varchar(2000)
declare cur_t cursor for
select name from sysobjects where xtype= 'U ' and status> =0 and name not in (select name from sysobjects where id in (select id from syscolumns
where id in (select id from sysobjects where type='U')
and name='CreateTime' ))
open cur_t
fetch next from cur_t into @tablename
while @@FETCH_STATUS = 0
begin
set @sql='alter table ' + @tablename + ' add CreateTime datetime '
exec (@sql)
fetch next from cur_t into @tablename
end
close cur_t
deallocate cur_tsql

上面是 全部没有 CreateTime 字段的 表中 插入 CreateTime 字段 ,加入其它字段能够修改 CreateTime数据库

 


select name from sysobjects where id in (select id from syscolumns
where id in (select id from sysobjects where type='U')
and name='CreateTime' )fetch

查询出 数据库  全部表中 有 CreateTime 字段的表名table

select id from sysobjects where type='U'object

查询 全部表 id   将 id 换成 name 则是查出全部表名date

相关文章
相关标签/搜索