• 常用SQL语句


    SQL数据定义

    1、create

    create table student

    (stuid varchar(10) primary key,

    name varchar(10)

    );

    2、insert

    insert into student values(10009,'xiaoming');

    3、drop

    drop table student;

    4、delete

    delete from student;     //删除所有元组

    delete from student

    where name='xiaoming';                //删除特定元组

    5、alter 

    alter table r add A D;               //A是属性名字,D是属性域

    alter table r delete A;             //删除属性A,这个不是普遍支持的

    SQL查询

    6、select     //查询,distinct,去除重复元组

    select name,salary*1.3

    from student,teachs                    //例子虽然举的不合适,但是这笛卡儿积

    where student.ID=teachs.ID;         //留下符合条件的元组

    7、natural join                        //自然连接

    select name,salary*1.3

    from student natural join teachs;           //跟第6句意思一样

    附加的基本运算

    8、as  //更名运算

    9、like

    select name

    from department

    where building like ‘%Waston%’;     //匹配任何包含Waston的子字符串

    10、order by        //排序,desc、asc

    11、between   and  //区间内

    集合运算

    12、union    //并运算,自动去除重复项

    (select id

    from section

    where semeter='Fall')

    union

    (

    select id

    from section

    where semeter='Spring'

    );

    13、intersect       //交运算,自动去除重复的    intersect all   保留重复项

    14、except     //差运算

    16、avg、max、min、sum、count    //聚集函数

    17、group by     //分组聚集,任何出现在select中的属性要么出现在group by中,要么被聚集,否则会报错

    select name,avg(salary) as avg_salary

    from instructor

    group by name;

    嵌套子查询

    18、in、not in

    19、>=some 、>=all 、  <>all     //集合的比较

    20、unique     //将返回true值

    21、having     //作用在group by后面

    数据库的修改

    22、update 

    update student

    set age=age+1

    where age<20;      

    视图          

    23、view

    create view student_view as                       //创建视图

    select id

    from section

    where semeter='Spring'

    索引

    24、index

    create index student_index on student(id);        // 创建视图

    权限

    25、grant          //授权,SQL标准包括select、insert、update和delete权限

    grant <权限列表>

    on <关系名或视图名>

    to <用户/角色列表>

    26、revoke   //收回权限

    revoke <权限列表>

    on <关系名或视图名>

    from <用户/角色列表>

  • 相关阅读:
    转:孙振耀谈人生(推荐)
    自绘按钮的实现
    数据结构知识
    Direct Show采集图像实例
    视觉跟踪
    改变对话框控件的颜色
    笔试题
    CBitmapButton的使用
    Rotor (SSCLI) 2.0 登场!
    Under the hood: 从Win32 SEH到CLI异常处理模型
  • 原文地址:https://www.cnblogs.com/girl1314/p/11504507.html
Copyright © 2020-2023  润新知