zoukankan      html  css  js  c++  java
  • ORACLE常用操作指南积累

    字段修改

    1、假设字段数据为空,则不管改为什么字段类型,可以直接执行:
    alter table tb modify (name nvarchar2(20));
    2、假设字段有数据,则改为nvarchar2(20)可以直接执行:
    alter table tb modify (name nvarchar2(20));
    3.新增字段
    alter table 表名 add 新增字段名 (类型+长度);
    案例
    alter table DAILY_SALES_REVENUE add first_code VARCHAR2(10) ;

    在某列后新增字段
    Oracle在表中指定位置增加字段:
    1. 新建别名表test2, 在指定位置添加列(占位置:d as pName)。
    create table test2 as select d as pName, d from test
    2. 清空新增字段的值。
    update test2 set pName=null
    3. 修改字段的类型。
    alter table test2 modify(pName varchar2(20))
    4. 删除原来的表test。
    drop table test
    5. 重命名表为test。
    rename test2 to test

    1. 更新字段名称
    alter table table_name rename column column_old to column_new;
    2. 添加字段
    alter table table_name add COLUMN_NAME varchar(10);
    3. 删除字段
    alter table table_name drop column COLUMN_NAME;
    4. 添加字段并赋值
    alter table table_name add COLUMN_NAME NUMBER(1) DEFAULT 1;
    5. 修改字段值
    update table_name set filedname = value where filedname = value;
    6. 修改字段数据类型
    alter table table_name modify filedname varchar2(20);

    复制备份一个表

    1:创建一个表new_table和old_table表结构一样(没有old_table的记录)
    create table new_table as select * from old_table where 1=0;
    2:创建一个表new_table和old_table表结构一样(有old_table的记录)
    create table new_table as select * from old_table;
    3:复制一个表数据到另一个表
    insert into new_table select * from old_table;

    各类查询

    -- 查询 表被那个地方使用过
    SELECT * from user_source a where upper(text) like '%表名%';
     
    所有用户及其权限命令
     
    1、查看所有用户
    select * from dba_user;
    select * from all_users;
    select * from user_users;
    2、查看用户系统权限
    select * from dba_sys_privs;
    select * from all_sys_privs;
    select * from user_sys_privs;
    3、查看用户对象权限
    select * from dba_tab_privs;
    select * from all_tab_privs;
    select * from user_tab_privs;
    4、查看所有角色
    select * from dba_roles;
    5、查看用户所拥有的角色
    select * from dba_role_privs;
    select * from user_role_privs;
    6、查看当前用户的缺省表空间
    select username,default_tablespace from user_users;
    7、查看某个角色的具体权限
    grant connect,resource,create session,create view to TEST;
    8、查看RESOURCE具有那些权限
    用SELECT * FROM DBA_SYS_PRIVS
    WHERE GRANTEE='RESOURCE
     
     
     
    索引操作

    单索引
    create index 索引名称 on table(column)
    删除索引
    drop index 索引名称
    复合索引
    create index WBSINDEX ON project_info(wbs,is_delete)
    查询某张表中所有索引
    select * from ALL_INDEXS where table_name = project_info
    查询某张表加了索引的列
    select * from ALL_IND_COLUMN where table_name = project_info

    删除唯一索引
    第一步 删除表与索引之间的联系
    ALTER TABLE TABLENAME DROP CONSTRAINT PK_TABLENAME ;
    第二步 执行删除索引语句
    DROP INDEX PK_TABLENAME ;
    第三步 若要重新创建索引则执行
    create unique index PK_TABLENAME on TABLENAME (ID,NAME);

  • 相关阅读:
    Linux常用命令及详细说明 — 结合工作(侧重性能监控,包括CPU、内存、IO、网络、磁盘等)
    navicat连接不上Linux服务器上的mysql的解决办法
    Git之rebase、merge和cherry pick的区别详解—面试常问
    阿里《JAVA实习生入职测试题—2019最新》之答案详解(连载一)
    技术语言框架学习方法论
    阿里《JAVA实习生入职测试题—2019最新》之答案详解(连载二)
    C# 文件/文件夹一般操作(File、Directory)
    Log4Net 使用及组合公共类
    VmWare 15 设置Centos7 共享文件夹及问题记录
    Centos 7 使用(Service iptables stop/start)关闭/打开防火墙 Failed to stop iptables.service: Unit iptables.service not loaded.
  • 原文地址:https://www.cnblogs.com/crazycomputers/p/15745117.html
Copyright © 2011-2022 走看看