日期:2014-05-16 浏览次数:20453 次
由于自己是做软件测试的,自学对应自身需求,或公司对测试人员的基本要求;
基本命令
conn 连接数据库
disc 断开数据库
show user; 显示当前用户
set linesize XX; 修改查询结果行数的显示
set pagesize XX; 修改查询结果一行字符数显示
1.创建用户
create user name identified by password ;
删除用户
drop user name;
alter user name identified by mod_password;
2.用户授权
先看下数据有哪些角色可以来授权:
select * from dba_roles;
显示的名称都可以授权给新的用户进行使用
grant connect to name;
3.创建表
create table 表名(a number(4),b char(5),.....);
删除表
drop table 表名;
4.添加记录
insert into 表名 values('XXX','XXX'.......);
删除记录
delete from 表名;
5.保存点
savepoint 保存名称;
6.恢复点
rollback to 保存名称;
7.复制记录
insert into user('字据1','字据2') select * from table_name;
8.统计行数count
select count(*) from table_name; --------------*为字据名称
9.消除重复行
seletc distinct * from table_name;
10.排序问题 order by & order by ****desc
升序:select * from table_name order by 字据;
降序:select * from table_name order by 字据 desc;
11. in \ like \ and 查询方法
创建abc表
create table abc(name char(4),no number(4));
添加记录
insert into abc values('123','123');
insert into abc values('123','23');
in 用法:***************************************
select * from abc where name in (123,23);
like用法****************************************
select * from abc where name like '_2%';
and 用户******************************************
select * from abc where no>1 and no<999;
12.多表查询
创建表
create table ax(name chare(4),no number(4));
create table bc(name chare(4),no number(4));
多表查询
select a.name,b.name from ax a,bc b where a.no=b.no;
例如:查询no为4的多表查询
select a.name,b.name from ax a,bc b where a.no=b.no and no='4';
13.单行子查询(重点是查询条件与括号的显示值一致====table_no=(select table_no....
select * from table_name where table_no=(select table_no from table where name='XX');
14.多行子查询
显示相同no的记录______in
select * from table_name where table_no in (select distinct table_no from table where name='XX');
显示大于子查询的记录_____all
select * from table_name where table_no > all( select table_no from table where name='XXX');
任一table_no比name大的记录
select * from table_name where table_no > any( select table_no from table where name='XXX');
**********************************************************************************************2012/12/7
15.自连接=连接同一表的记录
问题:查询员工名称与上司名称
select table_A.name as "员工名称",table_B.name as "上司名称" from table_work table_A, table_worker table_B where table_A.no=table_B.workno
继续学习…………