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. [bzoj4281][ONTAK2015]Związek Harcerstwa Bajtockiego_倍增LCA

    Związek Harcerstwa Bajtockiego bzoj-4281 ONTAK-2015 题目大意:给定一棵有n个点的无根树,相邻的点之间的距离为1,一开始你位于m点.之后你将依次收到k ...

  2. 1、Java并发性和多线程-并发性和多线程介绍

    以下内容转自http://ifeve.com/java-concurrency-thread/: 在过去单CPU时代,单任务在一个时间点只能执行单一程序.之后发展到多任务阶段,计算机能在同一时间点并行 ...

  3. easyui根据id获取列索引

    easyui根据row中的某个元素获取该列的索引,看了下api好像没有直接的方法,那只能自己写了 首先,id只是一个概念,不一定非得id,只要该列是唯一值,或者是主键就行. 假如我的列是这样的结构 { ...

  4. http://www.cnblogs.com/sprinkle/

    http://www.cnblogs.com/sprinkle/ http://www.cnblogs.com/sprinkle/

  5. C# 控制台程序如何输出Messagebox

    1 添加如下引用   2 添加引用和Messagebox的代码.   3 测试可行                

  6. Tomcat启动一半闪退问题解决

    近期刚刚接触Tomcat.对其还不是非常了解. 在这几天,遇到一个Tomcat启动闪退的问题.通过查阅各种资料.算是完美解决.在此分享给朋友们. 首先.确定你的问题在哪里.有两个方法,你能够通过日志去 ...

  7. iOS tableview cell 的展开收缩

    iOS tableview cell 的展开收缩 #import "ViewController.h" @interface ViewController ()<UITabl ...

  8. Ubuntu虚拟机安装遇到的各种坑

    配置 13年Macbook Pro 虚拟机环境 Parallels Desktop Linux 版本 Ubuntu 16.04 1.分辨率问题 进入只有一种分辨率 终端输入 sudo xdiagnos ...

  9. struts <s:iterator>两个list嵌套循环,对象属性交叉使用

    两个list:List<CreateTableColumn> createTableColumnList,List<Map<String, Object>> tab ...

  10. POJ3254 状压dp

                                                                                                    Corn ...