zoukankan      html  css  js  c++  java
  • heima-Oracle学习-day1

    play1

    --创建表空间
    create tablespace itheima
    datafile 'C:appDataitheima.dbf'
    size 100m
    autoextend on
    next 10m;
    
    --删除表空间
    /*drop tablespace itheima;*/
    
    -- 创建用户
    create user itheima
    identified by itheima
    default tablespace itheima;
    
    --给用户授权
    --oracle 数据库中常用角色
    connect -- 连接角色,基本角色
    resource --开发者角色
    dba      --超级管理员角色
    
    -- 给lewen 用户授权dba角色
    grant dba to itheima;
    
    --切换到lwen用户下
    -- c#lewen 登录名
    -- 创建一个person表
    
    create table person(
           pid number(20),
           pname varchar2(10)
    );
    
    --- 修改表结构
    -- 添加一列
    
    alter table person add (gender number(1)); -- 存1或2
    
    
    -- 修改列类型
    alter table person modify gender char(1);
    
    -- 修改列名称
    alter table person rename column gender to sex;
    
    -- 删除一列
    alter table person drop column sex;
    
    -- 查询表中记录
    select * from person
    
    ---- 添加一条记录
    insert into person (pid,pname) values (1,'小明');   -- 脏数据
    -- 提交事务
    commit;
    
    
    -- 修改一条记录
    update person set pname='小马' where pid=1;
    commit;
    
    
    ---- 三个删除
    -- 删除表中全部记录
    delete from person;
    -- 删除表结构
    drop table person;
    
    -- 先删除表,再创建表。效果等同于删除表中全部记录。
    -- 在数据量大的情况下,尤其在表中带有索引的情况下,该操作效率高。
    -- 索引可以提供查询效率,但是会影响增删改效率。先删除索引
    truncate table person;
    
    
    ---- 序列不真的属于在何一张表,但是可以逻辑和表做绑定。
    --—- 序列:默认从1开始,依次递增,主要用来给主键赋值使用。
    ----dual:虚表,只起为了补全语法,没有在何意义。
    
    create sequence s_person;
    select s_person.nextval from dual;
    select s_person.currval from dual;  -- 当前值
    
    
    ---- 添加一条记录
    insert into person (pid,pname) values (s_person.nextval,'小明');   -- 脏数据
    commit; -- 提交事务
    
    
    select * from person;
    
    
    ----scott用户,密码tiger。
    --- 需要解锁 scott
    alter user scott account unlock;
    -- 解锁密码[此句也可以用来重置密码]
    alter user scott identified by tiger;
    
  • 相关阅读:
    bzoj3993: [SDOI2015]星际战争
    bzoj3583: 杰杰的女性朋友 && 4362: Graph
    bzoj2260: 商店购物 && 4349: 最小树形图
    老oj3444 && Pku3241 Object Clustering
    bzoj3754: Tree之最小方差树
    bzoj2215: [Poi2011]Conspiracy
    老oj曼哈顿最小生成树
    bzoj2180: 最小直径生成树
    棋盘问题
    油田 Oil Deposits
  • 原文地址:https://www.cnblogs.com/wenyule/p/12789654.html
Copyright © 2011-2022 走看看