SQL数据库语句

查询语句
select   *   From  authors

对字段进行查询
select  au_lname,an_fname,city  From  authors

满足特定条件搜索
select  an_lname,an_fname,city  From  authors  Where  city = ' Oakland '

复杂条件搜索
select   *   From  sales  Where  qty > 25   and  odr_date  Between   ' 1993-1-1 '   and   ' 1994-1-1 '
select   *   From  sales  Where  (qty < 25   or  qty > 40 and  ord_date < ' 1994-1-1 '    // 搜索qty小于25或大于40并且ord - date小于1994年1月1日的数据

模糊查询
select   *   From  authors  Where  au_lname  LIKE   ' S '   //搜索表authors中au_lname字段以S开头的数据 
                                                      S通配多个字符   ?通配一个字符

排序 ORDER BY 语句
    升序以ASC标识(默认)
    降序以DESC标识
select   *   From  sales  ORDER   BY  qty
select   *   From  sales  Where  qty < 30   ORDER   BY  qty  DESC     //  搜索表sales中qty字段中大于30的数据并以降序排列

限定查询
select   distinct  stste Form authors    // distinct操作符  state字段

统计(对限定内容统计)
select   Count (state)  From  authors    // 统计有多少个state有相同的
select   Count ( Distinct  state)  As  stst_num  From  authors     // 查询有几个不同的state,统计为列名stst_num的

Max函数 数值类型字段的最大值
Min函数 数值类型字段的最小值
Avg函数 数值类型字段的平均值

插入记录INSERT
   在sales表中插入一条新记录
Insert  sales(stor_id,ord_num,ord_date,qty,payterms,title_id) value ( ' 8043 ' , ' F335 ' , ' 1994-5-6 ' , ' Net40 ' , ' pc1035 ' )
在插入时如已指定所有字段的值,可以简写成
Insert  sales value ( ' 8043 ' , ' F335 ' , ' 1994-5-6 ' , ' Net40 ' , ' pc1035 ' )
查询创建是否成功
select   *   from  sales  Where  ord_date = ' 1994-5-6 '

修改记录UPDATE
UPDATE  authors  set  photo = ' 801826-0755 ' ,state = ' UT ' ,zip = ' 84152 '   where  au_id = ' 998-72-4000 '
select   *   From  authors  where  au_id = ' 998-72-4000 '

删除记录DELECT
 1.删除全部记录 
Delect tablename   // 表名
 2.删除满足条件记录的语句
Delect tablename  where  fieldn = valuen
 例:
Delect authors  where  au_id = ' 998-72-4000 '
select   * From  authors  where  au_id = ' 998-72-4000 '

转载于:https://www.cnblogs.com/net123/archive/2007/11/10/955441.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值