oracle数据库sql语句04
来源:互联网 发布:2016淘宝好评返现规则 编辑:程序博客网 时间:2024/06/16 22:38
alter table emp1 add (firstname number(5), lastname number(5));
alter table emp1 modify firstname varchar(20);
alter table emp1 drop (firstname, lastname);
alter table emp1 add constraint p_empno primary key(empno);
alter table emp1 add constraint P_f foreign key(deptno) references dept(deptno);
alter table emp1 add constraint check_sal CHECK(sal>=800 and sal<=8000);
select * from USER_INDEXES where table_name = 'EMP1'
create index emp1 on emp1(empno);
create index emp1 on emp1(deptno);
conn system/12345678
GRANT CREATE VIEW TO SCOTT; --赋予scott权限
conn scott/123456
create or replace view VIEW_01 as select empno, ename, sal from emp1 where sal > 2000;
create or replace view VIEW_02 as select deptno, job, count(empno) 人数, avg(sal) 平均工资 from emp1 group by deptno,job;
1、查询出所有的用户表
select * from user_tables 可以查询出所有的用户表
select owner,table_name from all_tables; 查询所有表,包括其他用户表
通过表名过滤需要将字母作如下处理
select * from user_tables where table_name = upper('表名')
因为无论你建立表的时候表名名字是大写还是小写的,create语句执行通过之后,对应的user_tables表中的table_name字段都会自动变为大写字母,所以必须通过内置函数upper将字符串转化为大写字母进行查询,否则,即使建表语句执行通过之后,通过上面的查询语句仍然查询不到对应的记录。
2、查询出用户所有表的索引
select * from user_indexes
3、查询用户表的索引(非聚集索引):
select * from user_indexes where uniqueness='NONUNIQUE'
4、查询用户表的主键(聚集索引):
select * from user_indexes where uniqueness='UNIQUE'
5、查询表的索引
select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.index_name and t.table_name='NODE'
6、查询表的主键
select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = 'P' AND cu.table_name = 'NODE'
7、查找表的唯一性约束(包括名称,构成列):
select column_name from user_cons_columns cu, user_constraints au where cu.constraint_name=au.constraint_name and cu.table_name='NODE'
8、查找表的外键
select * from user_constraints c where c.constraint_type = 'R' and c.table_name='STAFFPOSITION'
查询外键约束的列名:
select * from user_cons_columns cl where cl.constraint_name = 外键名称
查询引用表的键的列名:
select * from user_cons_columns cl where cl.constraint_name = 外键引用表的键名
9、查询表的所有列及其属性
方法一:
select * from user_tab_columns where table_name=upper('表名');
方法二:
select cname,coltype,width from col where tname=upper('表名');;
10.查询一个用户中存在的过程和函数
select object_name,created,status from user_objects where lower(object_type) in ('procedure','function');
11.查询其它角色表的权限
select * from role_tab_privs ;
查看索引个数和类别
select * from user_indexes where table_name='表名' ;
查看索引被索引的字段
SQL>select * from user_ind_columns where index_name=upper('&index_name');
PS:
查看某表的约束条件
SQL>select constraint_name, constraint_type,search_condition, r_constraint_name
from user_constraints where table_name = upper('&table_name');
SQL>select c.constraint_name,c.constraint_type,cc.column_name
from user_constraints c,user_cons_columns cc
where c.owner = upper('&table_owner') and c.table_name = upper('&table_name')
nd c.owner = cc.owner and c.constraint_name = cc.constraint_name
order by cc.position;
------以下两个都可以
select table_name,constraint_name,constraint_type from user_constraints
where table_name='大写的表名'
select table_name,constraint_name,constraint_type from dba_constraints
where table_name='大写的表名'
---------另外以下可以只查看表中的索引
select * from USER_INDEXES where table_name = '大写的表名'
下边的也可以
select * from ALL_INDEXes where table_name = '大写的表名'
阅读全文
0 0
- oracle数据库sql语句04
- oracle数据库SQL语句
- oracle数据库sql语句
- oracle数据库sql语句技巧
- Oracle数据库sql语句收藏
- Oracle 数据库监控SQL语句
- oracle数据库 sql语句应用
- Oracle 数据库常用Sql语句
- oracle数据库SQL语句详解
- Oracle数据库SQL语句大全
- oracle数据库sql语句优化
- oracle数据库的sql语句
- Oracle 数据库常用Sql语句
- Oracle数据库SQL语句学习
- Oracle数据库SQL常用语句
- oracle数据库常见SQL语句
- oracle数据库sql语句01
- oracle数据库sql语句02
- mac 安装nginx
- Ajax登录效果源码
- JAVA基础-语言
- linux下终端配置透明度
- Docker的革命性变革-宣布Docker企业版
- oracle数据库sql语句04
- java运行时数据区
- mycat1.6.5分片(范围)
- python圣斗士修炼(三):运算符
- 笔记-决策树
- Java: 接口和抽象类
- 一元多项式求导
- 幸运数
- 并发编程中的协程