三、SQL脚本导入导出一张或几张表
exp username/password@tnsname tables=(table1,table2……) file=Directory\xxx.dmp log=Directory\xxx.txt
导入同上,exp改为imp即可
四、构建备份表或中间表
create table tableName1 as select * from tableName2
该语句相当于SQL Server中的(要求tableName2表不存在,Oracle该语句无效)select * into tableName2 from tableName1
五、从其他表中拷贝数据到另一张表(要求tableName2表必须已存在)
insert into tableName2 select * from tableName1 where condition
若只想插入其中的几列
insert into tableName2(column1,column2……) select column, column1…… from tableName2 where condition
六、查看所有表及表空间信息
select * from user_tables
若想查看某一张表则可用select * from user_tables t where t.table_name like '%TABLENAME%' PS:查询条件中的tablename一定要为大写字母,或者可以用upper()函数转成大写字母,代码如下:select * from user_tables t where t.table_name like upper('%tableName%')
若想查看该表空间有多少表空间,可以用下面代码:
select * from user_tablespaces
若想查看某表空间有多少表,可以用下面代码:
select * from user_tables t where t.tablespace_name = upper('tablespaceName')
若想查看所有主外键关联关系,可以用下面代码:
select * from user_constraints u where u.constraint_name = upper('constraintName')
七、create tablespace、user
CREATE TABLESPACE ictmap
DATAFILE 'C:\Oracle\instantclient\ICTMAP.ora' SIZE 600M REUSE
AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL;
CREATE USER username IDENTIFIED BY password DEFAULT TABLESPACE ictmap TEMPORARY TABLESPACE temp;
GRANT CONNECT,RESOURCE,CREATE PUBLIC DATABASE LINK,CREATE VIEW,DROP PUBLIC DATABASE LINK TO username;
八、alter table
向表中增加一列:
ALTER TABLE table ADD column type;
删除表中的一列:
ALTER TABLE table DROP COLUMN column;
修改某列的属性:
ALTER TABLE table MODIFY column type;
更改列名:
ALTER TABLE table RENAME COLUMN column TO newcolumn;
修改表名:
ALTER TABLE table RENAME TO newtable;
新增约束:
ALTER TABLE table ADD CONSTRAINT definition;