oracle数据库——基本操作

一  创建数据库

开始——》oracle-oraDb10g_home1——》Configutation and Migration Tools——》Database Configuration Assistant——》下一步——》选择“创建数据库”,下一步——》选择“一般用途”,下一步——》设置“数据库名字”,下一步——》下一步——》设置“密码”,下一步——》一直下一步——》选择“创建数据库”。下一步——》完成——》确定——》退出

二 删除数据库

开始——》oracle-oraDb10g_home1——》Configutation and Migration Tools——》Database Configuration Assistant——》下一步——》选择“删除数据库”,下一步——》选择要删除的数据库的名字,完成——》是——》否。

三 连接刚刚新建的数据库、创建表空间、创建用户、给用户授权、退出

 1、首先,cmd输入命令:sqlplus /nolog,回车;然后,见上图。

2、往表空间中添加数据文件——在建立表空间时,若是约束了表空间的大小,那么一段时间之后,这个表空间就会被装满,无法再添加其他对象。这时候,就需要给表空间添加数据文件。

alter tablespace 表空间名字 add datafile '添加的位置\名字.dbf' size 空间大小 reuse autoextend on next 空间大小 maxsize unlimited;

3、删除表空间:drop tablespace 表空间名字;

4、删除表空间同时删除相应的数据文件:drop tablespace 表空间名字 including contents and datafiles;

5、创建表:create table 表名 (字段名称1  相应的数据类型1,字段名称2  相应的数据类型2,。。。。。);

6、修改表

   6、1修改字段类型

        比如将表中字段名称1对应的数据类型1修改为数据类型X

       alter table 表名 modify(字段名称1  相应的数据类型X);

   6、2添加一个字段(默认添加在表的最后)

    alter table 表名 add (欲添加的字段名称  相应的数据类型);

7、添加表的注释:comment on table 表名 is '注释‘;

8、重命名表:rename 原来的表名 to  新的表名;

9、删除表:drop table 表名;

10、查看表结构:describe imsitophonenumber;(仅输入这一行命令)

四 数据导出/备份:(不用connect,直接输入就行了)
1 将数据库TEST完全导出,用户名system 密码manager 导出到D:\daochu.dmp中
   exp system/manager@TEST file=d:\daochu.dmp full=y
2 将数据库中system用户与sys用户的表导出
   exp system/manager@TEST file=d:\daochu.dmp owner=(system,sys)
3 将数据库中的表table1 、table2导出
   exp system/manager@TEST  tables=(table1,table2)  file=d:\daochu.dmp
4 将数据库中的表table1中的字段filed1以"00"打头的数据导出
   exp system/manager@TEST file=d:\daochu.dmp tables=(table1) query=\" where filed1 like

'00%'\"

五 数据导入/还原:(不用connect,直接输入就行了)

imp 用户名/密码@数据库名字 full=y file=欲导入的文件的位置和名称 ignore=y;

六 创建索引
create index 索引名字 on 表名字 (字段名字,即想要给哪个字段建立索引);
可以对同一个表的不同字段建立索引,
最后一定要commit

原文地址:https://www.cnblogs.com/suinuaner/p/oracle.html