September 2010
M T W T F S S
« Jul    
 12345
6789101112
13141516171819
20212223242526
27282930  

Backup and Recovery Overview

1.Categories of Failures
.Statement failure
.User process failure
.user error
.Instance failure
.Media failure
.Network failure
Continue reading Backup and Recovery Overview

Managing User

1.Security Domain
Authentication Mechanism
. Data Dictionary
. Operating system
. Network

Syntax
Use the following command to create a new user:

1
2
3
4
5
6
7
8
9
10
CREATE USER user
IDENTIFIED {BY password | EXTERNALLY}
[ DEFAULT TABLESPACE tablespace ]
[ TEMPORARY TABLESPACE tablespace ]
[ QUOTA {integer [K | M ] | UNLIMITED } ON tablespace
[ QUOTA {integer [K | M ] | UNLIMITED } ON tablespace
]...]
[ PASSWORD EXPIRE ]
[ ACCOUNT { LOCK | UNLOCK }]
[ PROFILE { profile | DEFAULT }]

Continue reading Managing User

Managing Privileges

1.Two Types of Oracle user privileges

1
2
3
4
5
6
7
8
. System privilege:Enables users to perform particular actions in the database
. Object:Enables users to access and manipulate a specific object
. There is no CREATE INDEX privilege.
. CREATE TABLE includes the CREATE INDEX and the ANALYZE commands. The user
  must have a quota for the tablespace or must have been granted UNLIMITE TABLESPACE.
. Privileges such as CREATE TABLE, CREATE PROCEDURE, or CREATE CLUSTER include the dropping of these objects.
. UNLIMITED TABLESPACE cannot be granted to a role.
. For truncating a table in another schema, the DROP ANY TABLE privilege is necessary.

Continue reading Managing Privileges

我们说好的……

         被现实弄烦了,十月份、十一月份……满脑子的事情,却不知应该从哪入手。他们都说什么事都听我的,可是我觉得现在我最需要的是意见,是有人能和我一起商量一下,找出最省时省力省钱的办法来,可是现在的我就像是被世界抛弃了一样。

        今天的我仿佛看开了,什么朋友,什么爱人,以至于亲人,都各自活在自己的小天地中,而我又是活在谁的世界中呢?忽然很想念在这个时候能够给我帮助但现在却不在身边的人,在这个孤单的时刻,他们也许正在他们的生活中开心或者悲伤中,又或者和我一样,孤单中也在想念我这个曾经带给他们快乐的人。

        我厌倦了这种生活,一度沉浸在闲言碎语中打发时间,可是现在回头却发现,我已经渐渐地丢失了自己,这种日子让我感到空虚,曾经平静的心再也平静不下来了。没办法,活在这里就得依照这里的规则,可是世事一天一变,谁知道明天又会发生什么呢?恐慌又能怎么办?不安又能怎么办?只能厚着脸皮去面对一切,谁让这一切是我选择和不能选择的呢?

        今天我真真切切的体会到,每天搭伙吃饭的不叫朋友,每天闲聊的也不叫朋友,有事才来找你的而你有事却不陪你的也不叫朋友,朋友,不是心的较量,时间的沉淀会把每个人的样子清清楚楚的记录下来,最终在你生命中留下痕迹的才是真正的朋友。我不和有心眼的人交朋友,也不和算计别人的人交朋友,更不和在我需要却找一个生硬的理由来推拖的人交朋友,我希望友情是纯洁的,哪怕在这个世界上只有一个朋友。

        心潮起伏之时,无意中听到一首歌,是张靓颖的“我们说好的”。它仿佛把我带到了另一个空间,在那里,有大海有空空的街道,还有他,就算有眼泪那也是只属于我们的,心的或者伤心的,与其他人无关的。很喜欢里面的歌词。“我们说好绝不放开相互牵的手,可现实说过有爱还不够。。。。。。我们说好一起老去看细水常流。。。。”

张靓颖 – 我们说好的(正式版)

好吗 一句话就哽住了喉
城市 当背景的海市蜃楼
我们 像分隔成一整个宇宙
再见 都化作乌有
我们说好决不放开相互牵的手
可现实说过有爱还不够
走到分岔的路口
你向左我向右
我们都倔强地不曾回头
我们说好就算分开一样做朋友
时间说我们从此不可能再问候
人群中再次邂逅
你变得那么瘦
我还是沦陷在你的眼眸

好吗 一句话就哽住了喉
城市 当背景的海市蜃楼
我们 像分隔成一整个宇宙
再见 都化作乌有
我们说好决不放开相互牵的手
可现实说过有爱还不够
走到分岔的路口
你向左我向右
我们都倔强地不曾回头
我们说好就算分开一样做朋友
时间说我们从此不可能再问候
人群中再次邂逅
你变得那么瘦
我还是沦陷在你的眼眸
yiya yiya~~~
我们说好一起老去 看细水常流
却将会成为别人的某某
又到分岔的路口
你向左我向右
我们都强忍着不曾回头
我们说好下个永恒里面再碰头
爱情会活在当时光节节败退后

下一次如果邂逅
你别再那么瘦
我想一直沦陷在你的眼眸
这是无可救药爱情的荒谬

       

Maintaining Data Integrity

Maintaining Data Integrity
1.Methods to Guarantee Data Integrity
.Application code
.Database triggers
.Declarative integrity constraints

2.Types of Constraints
.NOT NULL
.UNIQUE
.PRIMARY KEY
.FOREIGN KEY
.CHECK

3.Constraint States
An integrity constraint can be enable(data is checked as it is entered or updated) or disabled(data that dose not confirm to the constraint’s rule is prevented from being entered).
An integrity constraint can be in one of the following states:
.DISABLE NOVALIDATE:Old data and new data will not be checked.And the index will be dropped.
.DISABLE VALIDATE:Any modification of the constrained columns is not allowed.In addition,the index on the constraint is dropped and the constraint is disabled.
.ENABLE NOVALIDATE:new data(will be inserted into table) check, old data(original data in the table) not check.If it’s on primary key ,novalid will still check the old data.
Enabling constraints in the novalidated state is most useful in data warehouse configurations that are uploading valid OLTP data.

.ENABLE VALIDATE:Old data and new data will be checked.When a constraint changes to enable validate from disabled state,the table is loced and all data in the table
is checked for soformity.This may cause DML operations such as a data load to wait,so it is advisable to move first from a disabled state
to enable novalidate,and then to enable validate.

Note:Unique or primary key moves from the DISABLE state to ENABLE state and there’s no existing index,a unique index is created automatically.
Similarly,when a unique or primary key moves from ENABLE to DISABLE and it is enabled with a unique index,the unique index is dropped.

Moving a single constraint from ENABLE NOVALIDATE state to ENABLE VALIDATE state dose not block reads,writes or other DDL statements.

4.Constraint Checking

Constraint check road
DML statement->Check nondeferred constraints->COMMIT->Check deefrred constraints

Nodeferred (Immediate) Constraints
Enforced at the end of every DML statement.A constraint that is defined as nondeferrable cannot be modified to be enforced at the end of transaction.

Deferred Constraints
Deferred constraints are constraints that are checked only when a transaction is commited.

A constraint that is defined as deferred can be specified as one of the following
.Initially immediate specifies that by default it should function as an immediate constraint unless explicitly set otherwise.
.Initially deferred specifies that by default the constraint should only be enforced at the end of the transaction

5.Changing the Enforcement of Constraints
.SET CONSTRAINTS statement

1
2
3
4
ALTER SESSION
   SET CONSTRAINT | CONSTRAINT[S]
     {constraint |ALL}
     {IMMEDIATE|DEFERRED}

The SET CONSTRAINT mode lasts for duration of the transaction or until another SET CONSTRAINTS statement resets the mode.
The SET CONSTRAINT statement is disllowed inside triggers.

.ALTER SESSION statement

ALTER SESSION
   SET CONSTRAINT[S] =
    {IMMEDIATE|DEFERRED|DEFAULT}

The ALTER SESSION statement imply setting ALL deferrable constraints statmemt applies to a current session only.

6.Primary and Unique Key Enforcement
Primary and unique keys are enforced using indexes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
IF Key_enabled='Yes' THEN
   IF Is an index availabe for use?='Yes'    
      IF Constraint Deferrable?='Yes' THNE      
         Use existing index;         
      ELSE        
        Use existing index;        
      END IF;   
   ELSE
      IF Constraint deferrable?='Yes' THEN         
         Create nonunique index;       
      ELSE       
        Create unique index;        
      END IF;   
   END IF;
ELSE
Do not use index;
END IF

7.Foreign Key Considerations

--------------------------------------------------------------------------------------------------
Desired Action                         |Applicaton sulution                                       |
--------------------------------------------------------------------------------------------------
Drop parent table                      |Cascade constraints                                       |
--------------------------------------------------------------------------------------------------
Truncate parent table                  |Disable or drop foreign key                               |
--------------------------------------------------------------------------------------------------
Drop tablespace containing parent table|Use the CASCADE CONSTRAINTS clause                        |
--------------------------------------------------------------------------------------------------
Perform DML on child table             |Ensure the tablespace constaining the parent key is online|
--------------------------------------------------------------------------------------------------

.The foreign key must be dropped before dropping the parent table.

DROP TABLE table CASCADE CONSTRAINTS

.The parent table cannot be truncated whithout dropping or disabling the foreign key.
.The foreign must be dropped before tablespace containing the parent is dropped.

1
DROP TABLESPACE tablespace INCLUDING CONTENTS CASCADE CONSTRAINTS

If there is no index on the foreign key on the child table, the Oracle server
locks the child table and prevents changes to ensure referential integrity. If there is an index on
the table, the referential integrity is maintained by locking the index entries and avoiding more
restrictive locks on the child table. If both tables need to be updated concurrently from different
transactions, create an index on the foreign key columns.
When data is inserted into or the foreign key column is updated in the child table, the Oracle
server checks the index on the parent table that is used for enforcing the referenced key.
Therefore, the operation succeeds only if the tablespace containing the index is online. Note that
the tablespace containing the parent table does not need to be online to perform DML operations
on the child table.
Oracle9i no longer requires a share lock on unindexed foreign keys when doing an update or
delete on the primary key. It still obtains the table-level share lock, but then releases it
immediately after obtaining it. If multiple primary keys are update or deleted, the lock is obtained
and released once per row.

8.Defining Constraings While Creating a Table
Syntax

1
2
3
4
5
6
7
8
9
10
11
12
13
column datatype [CONSTRAINT constraint]
{[NOT] NULL
|UNIQUE [USING INDEX index_clause]
|PRIMARY KEY [USING INDEX index_clause]
|REFERENCES [schema.]table [(column)]
[ON DELETE CASCADE]
|CHECK (condition)
}
constraint_state :==
[NOT DEFERRABLE|DEFERRABLE [INITIALLY
{IMMEDIATE|DEFERRED}]
]
[DISABLE|ENABLE [VALIDATE|NOVALIDATE]]

Defining a constraint from the type NOT NULL after creating a table is only possible with:

1
ALTER TABLE table_name MODIFY col_name CONSTRAINT constraint_name NOT NULL;

9.Defining Constraints After Creating a Table:Example

1
2
3
4
ALTER TABLE hr.employee
ADD (CONSTRAINT employee_dept_id_fk FOREIGN KEY(dept_id)
REFERENCES hr.department(id)
DEFERRABLE INITIALLY DEFERRED);

10.Guidelines for Defining Constraints
. Place indexes used for enforcing primary key and unique constraints in a tablespace different from that of the table.
. If data is frequently loaded in bulk into a table, it is preferable to disable the constraints,
perform the load, and then enable the constraints. If a unique index is used for enforcing a
primary key or unique constraint, this index needs to be dropped when the constraint is
disabled. Performance can be enhanced by using a nonunique index for enforcement of
primary key or unique constraints in such situations: either create the key as deferrable or
create the index before defining or enabling the key.
. If a table contains a self-referencing foreign key, use one of the following methods to load
data:
– Define or enable the foreign key after the initial load
– Define the constraint as a deferrable constraint
The second method is useful if data loads are performed frequently.

11.Using the EXCEPTIONS Table
.Create exception table use:$ORACLE_HOME/rdbms/admin/utlexcpt.sql
.Add constraint with exceptions into clause
eg:

1
2
ALTER TABLE table_name ADD CONSTRAINT constraint_name
UNIQUE(col_name);

You also can use the following statement to except the duplicated rows after data load.

1
2
3
ALTER TABLE table_name
ENABLE VALIDATE CONSTRAINT constraint_name
EXCEPTIONS INTO schema.exceptions;

12.Obtaining Constraint information
.DBA_CONSTRAINTS
.DBA_CONS_COLUMNS