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

相關文章
相關標籤/搜索