`
罗春桉
  • 浏览: 16022 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

SQL常用语句总结

SQL 
阅读更多
要点:
   1.语法:                                                     4.索引:
   2.表:创建表,针对表的增删改查。     5.存储过程:
   3.数据:增删改查。                                 6.触发器及锁...

一、SQL语言


1.主要操作语句:
    1.对数据库操作:show ; use ; alert;
  
   2.对表的操作:show ; desc ; drop ; alter;

   3.对数据的操作:insert; delete ;update ;select;


2.表:
    1.表的创建:

      create table [name] (
     [字段名] [类型] (not null) (auto_increment只有主键才有),
     [字段名] [类型] (not null)
     primary key(要作为主键的字段));

    2.表的操作:
       
      drop table [表名];//删除表

      alter table [表名]
     drop column [字段名];//删除某列

      alter table [表名]
     add  [字段名] [类型];//添加某列
    
      alter table [表名]
     modify [字段名] [类型] default'默认值';//给某字段设置默认值

      

3.数据:
    1.数据的定义:
      字符串类型char varchar longvarchar
     布尔值    boolean
     字节      bit
     整形      tinyint smallint integer bigint
     浮点型    real float double
     日期      date
     时间      time
    
    2.数据的操作:
      对一条记录的:
      插入      insert into [表名](要插入的字段名) value(,,,);
      删除      delete from [表名] where 条件;
      修改/更新 update [表名] set [字段1]= ,[字段2]= ,[字段3]= where 条件;
      清空      truncate table [表名];
      查询      见第三点

     3.多种查询
       Select简单查询:select*from [表名];
             结果排序:select*from [表名] order by [某字段] desc;
      
       条件查询:select语句后的where语句指定查询条件
              条件:
              多重条件:And or
              比较条件:=,>,<,!=,!<,not+比较条件
              所在范围:in(),not in()
              是否为空:Is null,is not null
              模糊匹配:like'%_\';%模糊匹配任意内容;_模糊匹配某字符;/转义;
            例子:
             
            Select*from userinfo where id>1 and id<5;
            Select*from userinfo where name='a' or id='1';
            Select*from userinfo where age in(19,20,21);
            Select*from userinfo where name like '_abc\%';
            Select userinfo.id,userinfo.name as 姓名 from userinfo;

        分组查询:
              Select[字段1],count([字段2])as num,..from[表名]group by [字段1/其他字段];
        联合查询:
         嵌套查询:
       
二、索引
       详见 数据库学习之<索引>
       
(待补充----->
三、存储过程
       理解:
       实现:
四、触发器
       理解:
       实现:
五、锁
       理解:
       实现:
)


分享到:
评论
1 楼 Q_tian 2012-04-14  
这真是个好东西

相关推荐

Global site tag (gtag.js) - Google Analytics