zoukankan      html  css  js  c++  java
  • Oracle 常用命令

    一 管理用户
    1 查询用户集合
    select username from dba_users;
    A 查询某个用户是否存在
    select username from dba_users where username='用户名'
    2 查询用户权限
    select * from dba_sys_privs where grantee='用户名'
    3 创建用户
    create user 用户名 identified by 密码;
    4 删除用户
    drop user wp cascade;
    5 切换用户
    A conn / as sysdba    //切换管理员
    b conn 用户名/密码    //切换普通用户
    6 细分授予权限
    A grant create session to wp;//授权登入权限
    B grant unlimited tablespace to wp;//授予zhangsan用户使用表空间的权限
    C grant create table to wp;//授予创建表的权限
    D grante drop any table to wp;//授予删除表的权限
    E grant create sequence,select any sequence to 用户//授予 用户查询和创建序列的权限
    7 给用户授予全部权限
    A grant
      create session, create any table, create any view ,create any index, create any procedure,
      alter any table, alter any procedure,
      drop any table, drop any view, drop any index, drop any procedure,
      select any table, insert any table, update any table, delete any table
      to wp;
    B grant all to wp;  
    8 用户之间表访问的权限授予
    A grant select on tablename to zhangsan;//授予zhangsan用户查看指定表的权限
    B grant drop on tablename to zhangsan;//授予删除表的权限
    C grant insert on tablename to zhangsan;//授予插入的权限
    D grant update on tablename to zhangsan;//授予修改表的权限
    E grant insert(id) on tablename to zhangsan;
    F grant update(id) on tablename to zhangsan;//授予对指定表特定字段的插入和修改权限,注意,只能是insert和update
    G grant alert all table to zhangsan;//授予zhangsan用户alert任意表的权限
    9 取消用户权限
    A revoke delete any table from wp;//取消用户删除权限,其他于此类似
    B revoke
      create session, create any table, create any view ,create any index, create any procedure,
      alter any table, alter any procedure,
      drop any table, drop any view, drop any index, drop any procedure,
      select any table, insert any table, update any table, delete any table
      from wp;
     
     二 管理表
     1  创建表  
     create table 表名;
     A 主键  primary key
     C 设置约束 constraint
     2 删除表  
     drop table 表名
     3 修改表名
     rename 原表名 to 新表名
     4 查询表结构
     DESC 表名
     5 清除表数据
     delete from 表名
    6 清空删除表  
     PURGE recyclebin; 
    7 彻底删除表
    drop table 表名 purge
    
     三 字段操作
     1 增加字段
     A 增加单字段  
     alter table 表名 add 字段名 数据类型;
     B 增加多字段
     alter table demo1 add(字段名 数据类型, ......依此类推);
     2 删除字段
     alter table 表名 drop column 字段名;
     3 修改字段名称
     ALTER TABLE 表名 RENAME COLUMN 旧字段名 TO 新字段名;
     4 修改字段类型
     ALTER TABLE 表名 MODIFY  字段名 新字段类型;
     
     四 注释
     1 查询表注释
    select comments from user_tab_comments where table_name='表名';//需要注意的是表名需要大写,相应的还有dba_tab_comments,all_tab_comments,这两个比user_tab_comments多了ower列。
     2 增加表注释
     comment on table demo1 is 注释;
     3 查询表字段注释
       SELECT TABLE_NAME,COLUMN_NAME,COMMENTS FROM USER_COL_COMMENTS WHERE TABLE_NAME = '表名';//需要注意的是表名需要大写
     4 增加字段注释
     comment on column 表名.列名 is '注释';
     
     五 序列
     1 查询用户序列
      select sequence_name,sequence_owner from ALL_SEQUENCES where sequence_owner='用户名';//注意用户名得大写
     2 增加序列
     create sequence demo1_seq minvalue 最小值 maxvalue 最大值 start with 1 increment by 1 cache 10;
     3 查询序列
    select * from ALL_SEQUENCES where sequence_name='序列名';//注意序列名需要大写
     4 删除序列
     drop sequence DEMO1_SEQ;
    5 或许序列值
    序列名.nextval
    
    六 触发器
    1 查询触发器
    2 增加触发器
    3 删除触发器
    
     
     
     
     
    
     
  • 相关阅读:
    标签最低高度设置minheight不兼容
    字体综合属性(font)写法顺序为
    让IE6、IE7、IE8支持CSS3的圆角、阴影样式
    微信小程序3D轮播图
    微信小程序左滑删除
    android ble 蓝牙4.0开发日志(四)
    Windows邮件服务器hMailServer,网页前端访问平台Webmail搭建
    邮件服务器hMailServer管理工具hMailServer Administrator汉化
    蓝牙设计
    Windows下搭建免费、开源的邮件服务器hMailServer
  • 原文地址:https://www.cnblogs.com/ak23173969/p/4999328.html
Copyright © 2011-2022 走看看