建表
1、创建表空间:
create tablespace ysf(表空间名称) datafile ‘d:\ysf.dbf’ size 1024M;(这里的d:\ysf.dbf是你自己指定的,不用新建)
2、创建用户: create user ysf(用户名) identified by ysf(密码) default tablespace ysf;(表空间名称) (创建用户同时指定表空间)
3、给用户指定表空间: alert user ysf(用户名) default tablespace ysf;(表空间名称)
4、给用户授权: grant dba to ysf; 角色有:connect、resource、dba
5、删除用户: drop user ysf cascade;( 级联关系也删除掉)
以下sql查询表空间,可以把用户列出来。
SQL> select * from v$tablespace;
在cmd中输入: sqlplus / as sysdba 可以登录数据库,会出现 SQL>,此时可以输入sql语句,输入时,末尾的分号千万不能少!
添加字段:
alter table 表名 add (字段名 varchar2(32));
添加字段注释:
comment on column 表名.字段名
is ‘新加字段’;
赋权限、建同义词
新建表后可能会有多个用户同时操作这张表,所以可以给用户赋权限:
grant select,insert,update,delete,all on t_user(表名) to ysf(用户);
若用户较多或涉及数据库不在同一服务器上,可创建同义词,适用多个用户操作表和不同一个数据库服务器上的操作,同时可节约空间。
create public synonym t_user(同义词名称)) for ysf.t_user(表名);
数据导入、导出:
oracle导入数据:直接在cmd中输入:
imp ysf/ysf@orcl file= d:\data\xxxx.dmp full=y ignore=y
注意: oracle导出数据成dmp文件时,要处理空表!
查询当前用户下的所有空表: select table_name from user_tables where num_rows=‘0’
执行: select ‘alter table ‘||table_name||’ allocate extent;’ from user_tables where num_rows=0 or num_rows is null
- 将数据库orcl完全导出
exp system/manager@orcl file=d:\orcl_bak.dmp full=y - 将数据库中system用户的表导出
exp system/manager@orcl file=d:\system_bak.dmp owner=system - 将数据库中表table1,table2导出
exp system/manager@orcl file=d:\table_bak.dmp tables=(table1,table2) - 将数据库中的表user中的字段phone以"139"开头的数据导出
exp system/manager@orcl file=d:\mobile_bak.dmp tables=user query="where phone like ‘139%’ "