zoukankan      html  css  js  c++  java
  • Oracle 数据库操作

    1、连接数据库: conn 用户名/密码@服务名(一般情况下与数据库名字相同)[as sysdba]

      断开连接:disconn

    2、启动数据库:1、startup(启动实例->加载数据库->打开数据库)

            2、startup nomount(启动实例)

            3、startup mount(启动实例->加载数据库)

      关闭数据库:1、shutdown normal(不允许新的连接,等待会话结束(等待所有用户退出),等待事务结束,做一个检查点并关闭数据文件。启动时不需要实                    例恢复)

            2、shutdown transactional(不允许新的连接,不等待会话结束,等待事务结束,做一个检查点并关闭数据文件。启动时不需要实例恢复)

            3、shutdown immediate(不允许新的连接,不等待会话结束,不等待事务结束,做一个检查点并关闭数据文件。没有结束的事务会自动                        rollback。启动时不需要实例恢复)

            4、shutdown abort(不允许新的连接,不等待会话结束,不等待事务结束,不做检查点并没有关闭数据文件。启动时自动进行实例恢复)

    3、在startup mount 状态下,打开数据库:alter database open;

    4、在数据库open状态下,查询用户表:select  table_name from user_tables

                查询所有表:select table_name from all_tables

                查询dba表:select table_name from dba_tables

                查询某个用户的表:select table_name from ***_tables where owner='用户名'(***为user、all、dba之一)

    5、查询数据库文件名字和ID:select file_name,file_id from dba_data_files;

    6、表空间操作:

          1)删除操作:drop tablespace 名字 [ including contents and datafiles];(如果不加中括号中的语句,则不会删除表空间对应的数据文件)

          2)创建操作:

                (1)临时表空间:create temporary tablespace 名字

                        tempfile '绝对路径' size 50M

                        autoextend on next 20M maxsize 200M

                        extent management local;

                (2)数据表空间:create tablespace 名字

                        logging

                        datafile '绝对路径' size 50M 

                        autoextend on next 20M maxsize 200M

                        extent management local;

          3)修改操作:

                (1)关闭表空间的自动增长:alter database datafile 文件路径 autoextend off;

                (2)打开表空间的自动增长:alter database datafile 文件路径 autoextend on;

                (3)设置数据库默认表空间:alter database default tablespace 表空间名;

                (4)设置用户的默认表空间:alter user 用户名 default tablespace 表空间名; 

                (5)查看用户默认表空间:select username,default_tablespace from dba_users where username='用户名'

                (6)修改表空间名字:alter tablespace XXX rename to YYY;

                (7)更改表空间的数据文件路径:

                    1、在线情况:alter tablespace tablespace_name offline;

                            host copy D:\oradata\数据文件  G:\oradata\数据文件;

                            alter tablespace 表空间名 rename datafile 'D:\oradata\数据文件' to 'G:\oradata\数据文件';

                            alter tablespace 表空间名 online;

                    2、不在线情况:startup mount;                

                             host copy D:\oradata\数据文件  G:\oradata\数据文件;

                              alter tablespace 表空间名 rename datafile 'D:\oradata\数据文件' to 'G:\oradata\数据文件';

                            alter database open;

                 (8)更改数据文件的大小:alter database datafile '全路径的数据文件名称' resize ***M;

                 (9)添加数据文件:alter tablespace 表空间名 add datafile '全路径的数据文件名称'  ***M [autoextend on];

                 (10)删除数据文件:alter tablespace 表空间名 drop datafile '全路径的数据文件名称';

                 (11)查看表空间剩余空间:select tablespace_name,sum(bytes/1024/1024)

                            from dba_free_space group by tablespace_name

                 (12)查看数据文件使用情况:select file# ,name,status,enabled,bytes/1024/1024 M from v$datafile;

                              select tablespace_name,file_name,user_bytes/1024/1024 M from dba_data_files;

     

    7、查询表定义语句:select dbms_metadata.get_ddl('TABLE','表名','用户名') from dual;(表明和用户名区分大小写)

    8、修改数据库表所在空间:alter table 表名 move tablespace 表空间名;

  • 相关阅读:
    HTML5程序设计--SVG
    visual studio 2012 Github
    排序算法--鸡尾酒排序
    排序算法--归并排序
    排序算法--冒泡排序
    排序算法---插入排序
    外语学习的真实方法及误区
    学习新东西的唯一方法
    如何做好一个面试官——之学习篇
    求职者和面试官如何做好电话面试
  • 原文地址:https://www.cnblogs.com/handongdong/p/2902428.html
Copyright © 2011-2022 走看看