zoukankan      html  css  js  c++  java
  • 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 则是查出所有表名

  • 相关阅读:
    第八章 Libgdx输入处理(7)罗盘
    第六日
    第十日
    第五日
    第七日
    第九日
    第四日
    第三日
    使用EVM进行项目管理时的注意事项
    第八日
  • 原文地址:https://www.cnblogs.com/awake-insist/p/7053493.html
Copyright © 2011-2022 走看看