数据库常用命令
- 数据表快速备份
快速备份表语法
create table_bak as select * from table
如果备份表和被备份的表结构完全一致则可以直接写
insert into table2 select * from table1
如果备份表和被备份的表结构不完全一致则可以写
insert into table2(id,col1,col2...) select seq.nextval,col1,col2.. from table1
- 建视图
语法
CREATE [OR REPLACE] [FORCE | NOFORCE | ] VIEW view
[ (alias [, alias] ...) ]
AS subquery
[ WITH CHECK OPTION [ CONSTRAINT constraint ] ]
[ WITH READ ONLY [ CONSTRAINT constraint ] ];
创建简单的视图
–创建视图
CREATE OR REPLACE VIEW v_table
AS
SELECT id 编号, account 账号, email 邮箱, mobile 电话, name 姓名, sex 性别, birth 生日
FROM buser;
–查询视图
SELECT * FROM v_table;
如何快速向数据库表里面插入Excel
1.pl sql
输入
select t.*,t.rowid from table
将Excel里面的数据复制过来点勾再提交就可以了
2.其他
下载NimbleText2.8.exe工具
sql优化常用方法
我在工作中遇到一个sql ,这个sql需要用到两个数据库里面的数据数据库A(oracle 9i)和数据库B (oracle 10i)
需要用到3张表,table1,table2,table3,其中table2和table3属于数据库A,table1属于数据库B
select * from table1@B t1,table2 t2 where t1.id=t2.id and NOT EXISTS (select id1 from table3 t3 where t1.id1=t3.id1)
这个sql在数据库A执行得挺快的不到1秒可以执行完
select * from table1 t1,table2@A t2 where t1.id=t2.id and NOT EXISTS (select id1 from table3@A t3 where t1.id1=t3.id1)
这个sql在数据库B执行得很慢的执行需要300多秒才可以执行完。
那么这种情况应该如何解决呢?