SQl添加、删除、修改语句

 SQl添加、删除、修改语句


SQL语句的添加、删除、修改虽然有如下很多种方法,但在使用过程中还是不够用,不知是否有高手把更多灵活的使用方法贡献出来?

添加、删除、修改使用db.Execute(Sql)命令执行操作
╔----------------╗
☆ 数据记录筛选 ☆
╚----------------╝
注意:单双引号的用法可能有误(没有测式)

Sql = "Select Distinct 字段名 From 数据表"
Distinct函数,查询数据库存表内不重复的记录

Sql = "Select Count(*) From 数据表 where 字段名1>#18:0:0# and 字段名1< #19:00# "
count函数,查询数库表内有多少条记录,“字段名1”是指同一字段
例:
set rs=conn.execute("select count(id) as idnum from news")
response.write rs("idnum")

sql="select * from 数据表 where 字段名 between 值1 and 值2"
Sql="select * from 数据表 where 字段名 between #2003-8-10# and #2003-8-12#"
在日期类数值为2003-8-10 19:55:08 的字段里查找2003-8-10至2003-8-12的所有记录,而不管是几点几分。

select * from tb_name where datetime between #2003-8-10# and #2003-8-12#
字段里面的数据格式为:2003-8-10 19:55:08,通过sql查出2003-8-10至2003-8-12的所有纪录,而不管是几点几分。


Sql="select * from 数据表 where 字段名=字段值 order by 字段名 [desc]"

Sql="select * from 数据表 where 字段名 like '%字段值%' order by 字段名 [desc]"
模糊查询

Sql="select top 10 * from 数据表 where 字段名 order by 字段名 [desc]"
查找数据库中前10记录

Sql="select top n * form 数据表 order by newid()"
随机取出数据库中的若干条记录的方法
top n,n就是要取出的记录数

Sql="select * from 数据表 where 字段名 in ('值1','值2','值3')"

╔----------------╗
☆ 添加数据记录 ☆
╚----------------╝
sql="insert into 数据表 (字段1,字段2,字段3 …) valuess (值1,值2,值3 …)"

sql="insert into 数据表 valuess (值1,值2,值3 …)"
不指定具体字段名表示将按照数据表中字段的顺序,依次添加

sql="insert into 目标数据表 select * from 源数据表"
把源数据表的记录添加到目标数据表

╔----------------╗
☆ 更新数据记录 ☆
╚----------------╝
Sql="update 数据表 set 字段名=字段值 where 条件表达式"

Sql="update 数据表 set 字段1=值1,字段2=值2 …… 字段n=值n where 条件表达式"

Sql="update 数据表 set 字段1=值1,字段2=值2 …… 字段n=值n "
没有条件则更新整个数据表中的指定字段值

╔----------------╗
☆ 删除数据记录 ☆
╚----------------╝
Sql="delete from 数据表 where 条件表达式"

Sql="delete from 数据表"
没有条件将删除数据表中所有记录)

╔--------------------╗
☆ 数据记录统计函数 ☆
╚--------------------╝
AVG(字段名) 得出一个表格栏平均值
COUNT(*|字段名) 对数据行数的统计或对某一栏有值的数据行数统计
MAX(字段名) 取得一个表格栏最大的值
MIN(字段名) 取得一个表格栏最小的值
SUM(字段名) 把数据栏的值相加

引用以上函数的方法:
sql="select sum(字段名) as 别名 from 数据表 where 条件表达式"
set rs=conn.excute(sql)
用 rs("别名") 获取统的计值,其它函数运用同上。

╔----------------------╗
☆ 数据表的建立和删除 ☆
╚----------------------╝
Create TABLE 数据表名称(字段1 类型1(长度),字段2 类型2(长度) …… )
例:Create TABLE tab01(name varchar(50),datetime default now())
Drop TABLE 数据表名称 (永久性删除一个数据表)

╔--------------------╗
☆ 记录集对象的方法 ☆
╚--------------------╝
rs.movenext 将记录指针从当前的位置向下移一行
rs.moveprevious 将记录指针从当前的位置向上移一行
rs.movefirst 将记录指针移到数据表第一行
rs.movelast 将记录指针移到数据表最后一行
rs.absoluteposition=N 将记录指针移到数据表第N行
rs.absolutepage=N 将记录指针移到第N页的第一行
rs.pagesize=N 设置每页为N条记录
rs.pagecount 根据 pagesize 的设置返回总页数
rs.recordcount 返回记录总数
rs.bof 返回记录指针是否超出数据表首端,true表示是,false为否
rs.eof 返回记录指针是否超出数据表末端,true表示是,false为否
rs.delete 删除当前记录,但记录指针不会向下移动
rs.addnew 添加记录到数据表末端
rs.update 更新数据表记录

 

DB2 数据库恢复的办法
===========================================================
DB2连接的问题
===========================================================
Problem
I create a connected datastore object in a servlet and then pass the connected datastore object to a method in a different

servelet to perform an operation. I frequently get DKException "[IBM][CLI Driver] CLI0125E Function sequence error.

SQLSTATE=HY010 " 
 
Cause
If the same datastore object is not property synchronized in a multithreading scenario, the following error is likely to

occur when performing operations on the datastore:

DKException
[IBM][CLI Driver] CLI0125E Function sequence error. SQLSTATE=HY010
 
 
Solution
This is a classic symptom of a threading problem. Most likely, the same datastore instance is used by multiple threads at the

same time.

Either strictly synchronize your access to the datastore object or have each thread use its own separate connected

DKDatastoreICM object.

Using separate datastore objects is the safest solution.
 


===========================================================
db2
=====&

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值