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 则是查出所有表名

sql 所有数据表中 插入字段的更多相关文章

  1. SQL语句 在一个表中插入新字段

    SQL语句 在一个表中插入新字段: alter table 表名 add 字段名 字段类型 例: alter table OpenCourses add Audio varchar(50)alter ...

  2. EF Core中,通过实体类向SQL Server数据库表中插入数据后,实体对象是如何得到数据库表中的默认值的

    我们使用EF Core的实体类向SQL Server数据库表中插入数据后,如果数据库表中有自增列或默认值列,那么EF Core的实体对象也会返回插入到数据库表中的默认值. 下面我们通过例子来展示,EF ...

  3. 使用PreparedStatement向数据表中插入、修改、删除、获取Blob类型的数据

    使用PreparedStatement向数据表中插入.修改.删除.获取Blob类型的数据 2014-09-07 20:17 Blob介绍 BLOB类型的字段用于存储二进制数据 MySQL中,BLOB是 ...

  4. 向mysql数据表中插入数据失败的原因

    1.案例代码: $sql1="insert into content(category,subject,content,username,release_date) values('{$ca ...

  5. Oracle中使用游标转换数据表中指定字段内容格式(拼音转数字)

    应用场景:将数据表TB_USER中字段NNDP的内容中为[sannanyinv]转换为[3男1女] 主要脚本:一个游标脚本+分割字符串函数+拼音转数字脚本 操作步骤如下: 1.创建类型 create ...

  6. SQL查询一个表中类别字段中Max()最大值对应的记录

      SQL查询一个表中类别字段中Max()最大值对应的记录 SELECT A.id, A.name, A.version FROM   DOC A, (SELECT id, MAX(version)  ...

  7. 使用python来反查数据表中的字段名

    1. 链接数据库 import psycopg2 conn = psycopg2.connect(user,host,port,database,password) cur = conn.cursor ...

  8. 触发器修改后保存之前的数据 表中插入数据时ID自动增长

    create or replace trigger t before update on test5 for each rowbegin insert into test55 values (:old ...

  9. 6-02使用SQL语句向表中插入数据

    插入语句的语法: INSERT INTO 表() VALUES(值列表) 注意事项: 1:每次插入一行数据,不能只插入半行或几列数据. 2:每一个数据值的数据类型.精度和小数位数必须与相应的列匹配. ...

随机推荐

  1. Kernel与用户进程通信

    测试IPv6 ready logo   rfc 3315的时候,遇到一个问题,要求在收到ICMPv6 RA的时候,DHCPv6  Client要发Solicit消息.在平常的应用中,都是启动DHCPv ...

  2. kafka-manager 的编译和使用(附安装包)

    kafka-manager 的编译和使用(附安装包) 学习了:https://my.oschina.net/wangjiankui/blog/653139

  3. .Net 与 Javascript 混合编程系列

    之前的文章有提到 edge 和 nodejs 交互,通过node的模块为C# 提供一些扩展,这个还是比較方便. 这里说下为什么要使用js. 1.SharpKit是一个用于在编译时将C#语言转换为Jav ...

  4. android的toogleButton和switch的使用方法

    这两个是button开关.监听CheckedChangeListener toggle_layout.xml: <? xml version="1.0" encoding=& ...

  5. hiho一下 第五十一周(有向图欧拉路径)51

    //////////////////////////////////////////////////////////////////////////////////////////////////// ...

  6. [Erlang危机](5.1.4)端口port

      原创文章,转载请注明出处:server非业余研究http://blog.csdn.net/erlib 作者Sunface 或port drivers15.   全程跟踪端口数会对诊断负载或进程泄漏 ...

  7. Codeforces Round #214 (Div. 2) C. Dima and Salad 背包

    C. Dima and Salad   Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to ...

  8. grep 并列查询 效率 且 或

    find / | grep -v python | grep -v xl_ | grep -v xiaole |grep redis [root@hadoop3 ~]# find / | grep - ...

  9. Keys.BACKSPACE Keys.SPACE

    browser.find_element_by_xpath(xp_newpage).send_keys(Keys.SPACE)browser.find_element_by_xpath(xp_newp ...

  10. ios31--NSThread

    // // ViewController.m // 03-掌握-NSThread基本使用 #import "ViewController.h" #import "XMGT ...