zoukankan      html  css  js  c++  java
  • 【HCIA Gaussdb】学习汇总-数据库管理(SQL语法 库表 索引操作)-5

    # 简单查询
    select * from table_reference
    # 创建表
    create table TB(staff_id int primary key , course_name char(50) , exam_date datetime);
    # 插入数据
    insert into TB values(10,"ljj","2019-10-1112:00:00")

    # distinct 消除重复列
    select table1.name,table2.name from table1,table2

    # left join 连接查询
    select a.name,b.name,a.number,b.number from a left join b on a.name=b.name

    # 子查询
    select * from a where number > (select avg(number) from a)
    create table a select * from b ; # 创建一个和B一样的表 并导入所有数据

    # 合并结果集
    select * from a union select * from b -----> a+b 除去相同部分
    select * from a union all select * from b ------> a+b 所有

    # 差异结果集
    select * from a minus/except select * from b ------a - b a除去所有和b相同的部分

    # 分组
    select * from a group by(number,name)

     # 创建分区表

    create table TB(id int primary key auto_increment,name char(30),time datetime, grade int) partition by range(id)(
    partition training1 values less than (100),
    partition training2 values less than (200)
    );

    # 新增列
    alter table TB add username char(50);
    # 删除类
    alter table TB drop username
    # 修改列
    alter table TB change username user varchar(10);
    alter table TB modify user varchar(20);

    # 删除表
    drop table TB;
    # 恢复表
    flashback table TB to before drop

    # 创建索引
    create index idx_posts on TB(id) online;
    # 删除索引
    drop index idx_posts on TB;

    # 创建视图
    create view v_all as select * from TB ;
    desc TB ==> describe TB 查看结构
    # 删除视图
    drop view if exists v_all;

    创建序列
    # 创建 seq_auto_extend序列生成器 当前用户为该生成器的所有者 起点是10 最大值为200 自增步长为2
    create sequence seq_auto_extend start with 10 maxvalue 200 increment by 2 cycle;


    # 获取值 下一个值 或者当前值
    select seq_auto_extend {nextval | currval} from DUAL
    # 获取序列自增
    insert into test values( seq_auto_extend.nextval,'name')
    # 删除序列
    drop sequence if exists seq_auto_extend

     

     

     

     

  • 相关阅读:
    datatable一些用法续
    验证视图状态MAC失败
    datatable应用select方法后变成行数组的问题的解决
    [jQuery] html中两个select之间option元素的add与remove,多值上传
    [VBS] 使用vbs文件保证程序运行,并模拟键盘回车键
    [jQuery] 为table各行添加不同颜色的class
    [转]谈谈个人网站建设和经营
    [jQuery] jquery如何reset表单(form)
    兼容Firefox IE Chrome的onkeydown事件处理方法
    [bat] 使用bat文件保证指定程序运行
  • 原文地址:https://www.cnblogs.com/oscarli/p/12066715.html
Copyright © 2011-2022 走看看