设为首页 加入收藏

TOP

【oracleocp知识点二】(四)
2015-07-24 11:59:38 来源: 作者: 【 】 浏览:54
Tags:oracleocp 知识点
------------------------
T3
---------------------------------------------------------------------------
T4
---------------------------------------------------------------------------
T5
---------------------------------------------------------------------------
T6
---------------------------------------------------------------------------
还原scott资料用户
SQL>startup ?/rdbms/admin/utlsampl
SQL>drop user sctt scade;
SQL>select username,sid,serial# from v$session where username='SCOTT';
SQL>alter system kill session '44,21';
4.DDL的管理及操作
数据库对象:表 视图 序列 索引 同义词
命名规则:以字母开头、1-30字符、A-Z/a-z/0-9/_/$、字符开头
database link 128
库名 8
实例名 12
使用内部保留字,小写加上双引号即可
create table "user"....
alter table t1 modify (sal default null);
5.约束
自动命名(sys)、手动命名
列级约束 非空只能在列级定义 逗号隔开
表级约束 空格隔开
非空约束 not null constraint
SQL> create table b(id number not null);
Table created.


SQL> insert into b values(null);
insert into b values(null) *
ERROR at line 1:
ORA-01400: cannot insert NULL into ("SCOTT"."B"."ID")


SQL> alter table b modify (id null);
Table altered.


SQL> alter table b modify (id constraint b_id_null not null);
Table altered.
唯一性约束,自动简历唯一索引
SQL> create table c(id number unique);
Table created.
SQL> insert into c values(1);
1 row created.
SQL> /
insert into c values(1)
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.SYS_C0014385) violated
SQL> select constraint_name from user_constraints where table_name='C';


CONSTRAINT_NAME
------------------------------
SYS_C0014385
SQL>alter table c drop constraint sys_c0014385
Table altered.
SQL> alter table c add constraint a_id_u unique(id);
Table altered.
主键约束
一个表只能有一个主键
主键是唯一的并且非空
可以联合主键,联合主键要求每列都非空
主键唯一定位一行,所有主键也叫逻辑ROWID
主键不是必须的,可以没有
主键是通过索引实现的
索引的名称和主键的名称相同
外键约束
表级列级都可以定义
表级定义关联到子表中的列
执行删除操作时会出现错误,特别注意
检查约束 check constraint
check.....
违反约束 violating constraint
启用/停用 enable disable
建立表使用子查询
create table e as select * from emp; 新表不包含数据
create table e as select * from emp where 0=1;
alter table e read only; 使表只读
alter table e read write;
10g没有只读这个说法,所以只能建成一个试图
SQL> drop table c;
Table dropped.
SQL> show recyclebin;
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
C BIN$/o6ox8o+iMjgQ2YAqMDn3Q==$0 TABLE 2014-07-19:23:38:02
SQL> flashback table c to before drop;
Flashback complete.
SQL> alter table c add (name varchar2(20));
Table altered.
SQL> select * from c;


ID NAME
---------- --------------------
1
SQL> alter table c modify(name varchar2(28));
Table altered.
SQL> alter table c rename column name to dname;
Table altered.
SQL> alter table c drop column dname;
Table altered.
SQL> alter table c set unused column sex; //标记为不使用,在业务低峰期删除
Table altered.
SQL> alter table c drop unused columns;
Table altered.
SQL> alter table c drop column dname;
Table altered.
6.视图
本身就是一个查询语句
限制数据访问
复杂查询简单化
提供数据独立性
没有自己的数据,来源于查询结果
简单试图 一个表 dml不限制
复杂试图 一个或者多个表 dml限制
create [or replace] [force|noforce] view
.... as subquery
with check option ...
with read only ...
子查询不能包含order by
SQL> select * from session_privs;


PRIVILEGE
----------------------------------------
CREATE SESSION
UNLIMITED TABLESPACE
CREATE TABLE
CREATE CLUSTER
CREATE SEQUENCE
CREATE PROCEDURE
CREATE TRIGGER
CREATE TYPE
CREATE OPERATOR
CREATE INDEXTYPE
SQL> grant create
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 4/9/9
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇向Oracle数据库插入一条数据 下一篇oralce11g注册表卸载20140810

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Sphinx : 高性能SQL (2025-12-24 10:18:11)
·Pandas 性能优化 - (2025-12-24 10:18:08)
·MySQL 索引 - 菜鸟教 (2025-12-24 10:18:06)
·Shell 基本运算符 - (2025-12-24 09:52:56)
·Shell 函数 | 菜鸟教 (2025-12-24 09:52:54)