• 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_t

    上面是 所有没有 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' )

    查询出 数据库  所有表中 有 CreateTime 字段的表名

    select id from sysobjects where type='U'

    查询 所有表 id   将 id 换成 name 则是查出所有表名

  • 相关阅读:
    nowcoder 2020/6/20 J-小梁的背包
    nowcoder 2020/6/20 G-遗迹逃亡
    nowcoder 2020/6/20 C-杰尼杰尼
    nowcoder 2020/6/20
    我罗斯方块最终篇
    函数模板-集合模拟
    CF w4d3 B. Calendar
    绩效成绩(2)
    最需要改进三个的问题
    项目会议总结
  • 原文地址:https://www.cnblogs.com/awake-insist/p/7053493.html
Copyright © 2020-2023  润新知