Wednesday, 2 January 2013
Common SQL DDL Clauses
SQL statements.
allocate_extent_clause
constraints
deallocate_unused_clause
file_specification
logging_clausen parallel_clause
physical_attributes_clause
storage_clause
allocate_extent_clause
Purpose
Use the allocate_extent_clause clause to explicitly allocate a new extent for a
database object.
Explicitly allocating an extent with this clause does not change the values of the
NEXT and PCTINCREASE storage parameters, so does not affect the size of the next
extent to be allocated implicitly by Oracle.
Sunday, 30 December 2012
SQL Questions
In the Corelated query for every instance of outer query,inner query is executed and based on the result of the inner query outer query displays the records. In the sub query depending upon the inner query the outer query will be executed.
2)What is a dead lock?
If two or more users are accessing the same data source with different operations then all the user resources are in dead lock.
3)What are indexes ? Name the various types of Indexes available along with the usage (i.e where and which type of index has to be used?)
Index provides direct access to the data.
The Various types of indexes are Btree Index,Function-Based Index,Bitmap Index,Domain Index
4)What are Autonomous transaction ?
Autonomous is an independent transaction which has to be commited or rollbacked before passing the control to the parent transaction
5)What is mutation error and how to overcome this?
The mutation error is occurred when the row-level trigger access the same table while executing
6)What is a REF cursor?
REF cursor is used to return Record set to be returned from stored procedures,functions and packages.
ref cursor is a simple cursor but it is a datatype that allow developers to declare cursor variable
ref cursor has 2 types:-
strong ref cursor where we mention the return type with rowtype.
weak cursor where we don't mention return type.the advantage of this is that we can use weak cursor with any query.it is not rowtype bounded.
for ex:-strong ref cursor
type curvar_type is ref cursor return emp%rowtype;
weak cursor:-
type curvar_type is ref cursor is
7)What is a materialized view? Where should this be used and what are the advantages of using this?
Materialized views can hold data.They are used to update the remote data base.
8)What is a bulk collect?
Bulk collect facilitates high-speed retrieval of data.Bulk collect is used to fetch multiple rows into one or more collections,rather than individual variables or records.
9)What is dynamic SQL? How does a dynamic sql get fired?
Dynamic SQL is one which is executed at run time.
10)What is rowchaining?
Row Chaining is the storage of data in a chain of blocks.This primarily occurs in lob,clob,blob or big varchar2 data types.
11)what a table is dropped, what are the associated objects that get invalidated / dropped?
Objects which get invalid are Views,Synonyms. Objects which get droped are triggers,indexes,constaints
12) Difference between POST-TEXT-ITEM and WHEN-VALIDATE-ITEM?
Post-text-item will fire every time your cursor moves out of the field. It doesn't matter whether a value is newly entered or is being queried from database. This will fire in both cases.
When-validate-item will fire only when you have entered new value or you change an exixting value of an item. This means that you this will fire only when the status is CHANGED or NEW.
13) This Question is for diff b/w POST-TEXT-ITEM and WHEN-VALIDATE-ITEM?
Suppose you have two fields 'A' and 'B'
A will Have initial value --> 100
Now u want go to change the Value of A to ---> 200 (WVI will be fire)It will not give any error
And in When Validate Item u give a condition ---> If a<500
And u r assigning the value to 'A' in POST-TEXT-ITEM --> now the POST-TEXT-ITEm will fire and the value of 'A' should be change to 700.
Now the Question is WHEN-VALIDATE-ITEM will raise error or not?
Yes, It will fire and it will give an error message. for when validate item there is no need to change the value if it is change as internally then also WHEN-VALIDATE-ITEM will fire.
Question: Why are PL/SQL ref cursors important to PL/SQL performance?
Answer: The ref cursor is a "pointer" data types that allows you to quickly reference any cursor result (usually an internal PL/SQL table array) with data values kept in super-fast RAM.
Definition of a ref cursor
The name "ref cursor" can be confusing because a ref cursor variable is not a cursor, but a variable that points to a cursor. In essence, a ref cursor allows you to store the result of a "bulk collect" from a table (or any PL/SQL cursor return set) into a PL/SQL table (RAM array) and then reference the array with the ref cursor as a pointer. Here is a simple example of using a ref cursor.
Once you load a PL/SQL table (an in-RAM array), a ref cursor allows you to reference the array within your PL/SQL code without having to pass the array to a new procedure or function. Instead of passing the "baggage" of the actual RAM array, you simple pass the ref cursor, which points to the array values.
Important Sql Queries
select floor((trunc(sysdate) - to_date('01-JAN-01'))/365) years,
floor(mod((trunc(sysdate)- to_date('01-JAN-01')),365)/30 ) months ,
mod(mod((trunc(sysdate)- to_date('01-JAN-01')),365),30) days from dual;
2) How to delete a duplicate records in a table without using rowid?
delete from student
where id=(select max(id) from student group by id
having count(id||name)>1);
for emp table:
delete from emp
where empno=(select max(empno) from emp group by empno
having count(empno||ename)>1)
3)How to retrieve record number 70 from a table of 100 records?
(select * from emp
minus
select * from emp where rownum < 70)
intersect
select * from emp where rownum <=70;
4)What is Materialized View?
A materialized view is a database object that contains the results of a query. They are local copies of data located remotely or used to create summary tables based on aggregation of a tables data. Materialized views which store data based on the remote tables are also know as snapshots.
5) What is normalazation,types with examples. with queries of all types?
definition :1) normalization is organizing data in database.
2) Normalization is a process of eleminating the redundancy and increasing the integrity.
There are 5 normal forms. It is necessary for any database to be in the third normal form to maintain referential integrity and non-redundance.
First Normal Form:
Every field of a table (row,col) must contain an atomic value
Second Normal Form:
All columns of a table must depend entirely on the primary key column.
Third Normal Form:
All columns of a table must depend on all columns of a composite primary key.
Fourth Normal Form:
A table must not contain two or more independent multi-valued facts. This normal form is often avoided for maintenance reasons.
Fifth Normal Form:
is about symmetric dependencies.
Each normal form assumes that the table is already in the earlier normal form.
6)Check Constraint
CREATE TABLE temp(
eno NUMBER CONSTRAINTS pk_eno PRIMARY KEY,
gender CHAR(1) CHECK (gender IN( 'M','F')));
7)Whats the back end processes when we type "Select * from Table"?
First it will look into the System Global Area (SGA) weather the query is been exectued earlier.
If it exist, it would retrive the same output present in memory.
If not the query we typed is complied and the resulting parse tree and excution plan is been stored in SGA. Then query gets executed and output is given to the application.
8) PRE-QUERY
The Pre-Query trigger fires just before Form Builder issues the SELECT statement to the database, after the operator has defined the example record by entering query criteria in Enter Query mode.
9) POST-QUERY
The Post-Query trigger fires after the query has executed, when Form Builder is fetching records into the form. Post-Query fires once for each record retrieved into the form, which allows you to read and set the values of items in a fetched record before the operator sees them displayed in the block.
10) With out Using Like Function
substr(name,1,1)='S' and
substr(name,-1)='N'
Instr(name,'S')= 1 and
Instr(name,'N')= length(name)
'S'||Substr(name,2,length(name)-1)||'n' = name
11) How to find Duplicate Records
select * from emp where rowid not in ( select min(rowid) from emp group by ename);
12) Pivote table ( change rows as columns)
select decode( r, 1, to_char(sal), 2, sno)
from salary, (select rownum r from all_objects where rownum <= 2 )
where sno = 1
select stno,
max(decode(rn,1,course_code)) s1,
...
max(decode(rn,N,course_code)) sN
from ( select stno, course_code,
row_number() over (partition by stno order by course_code )
from t )
group by stno
13) Generating the Sequence Number without using Sequence
SELECT * FROM (SELECT LEVEL FROM dual CONNECT BY LEVEL < 10);
14)
SELECT EMPNO_ACN,EMPNO_DES FROM
(SELECT EMPNO EMPNO_ACN, RANK() OVER (ORDER BY EMPNO DESC) R FROM EMP ) A,
(SELECT EMPNO EMPNO_DES, RANK() OVER (ORDER BY EMPNO) X FROM EMP ) B
WHERE A.R = B.X
15)
What is the Difference between DBMS and RDBMS ?
Ans :
1. dbms is a single user system rdbms is a multiuser system
2. dbms do not store data in the form of tables while rdbms stores it in the form of tables.
3. most of dbms are not supporting client/server architecture as it is supported by rdbms.
4. most dbms do not support distributed databases
5. In DBMS store and retrieve small amount of Data In RDBMS store and retrieve large amount of Data
6. RDBMS is more secure than DBMS
7. in rdbms is relation is more important than object itself while dbms entity is more important
8. In DBMS tables are not related. In RDBMS tables are related
16)
Is there any function in oracle to check whether a value is numeric or not. I have a column which contains both numeric and alphanumeric data. I want to fetch only the numeric data from that column. Can anyone tell me how to do it?
Hi Anu,
There does not exists any build in function which checks for a numeric value instead you can write your own function as follows.
CREATE OR REPLACE FUNCTION Isnumber(p_num VARCHAR2) RETURN NUMBER
AS
a NUMBER;
BEGIN
a := p_num;
RETURN 1;
EXCEPTION WHEN OTHERS THEN
RETURN 0;
END;
/
This function can now be called in a SQL query which will retum 1 if the value passwd is numeric else it will return 0.
OR
select * from test where translate(a,'_0123456789','_') is null;
=====================================
Check Constraint
--------------------
ALTER TABLE suppliers
add CONSTRAINT check_supplier_name
CHECK (supplier_name IN ('IBM', 'Microsoft', 'Nvidia'));
How to see the Difference between two table coulmns:-
========================================================
scott@ORA817.US.ORACLE.COM> create table t1 as select * from emp where 1=0;
Table created.
scott@ORA817.US.ORACLE.COM> create table t2 as select * from t1;
Table created.
scott@ORA817.US.ORACLE.COM>
scott@ORA817.US.ORACLE.COM> alter table t2 drop column ename;
Table altered.
scott@ORA817.US.ORACLE.COM> alter table t2 modify job varchar2(10);
Table altered.
scott@ORA817.US.ORACLE.COM>
scott@ORA817.US.ORACLE.COM> column data_type format a10
scott@ORA817.US.ORACLE.COM> (
2 select 'IN T1, NOT T2', column_name,data_type,data_length
3 from user_tab_columns
4 where table_name = 'T1'
5 MINUS
6 select 'IN T1, NOT T2', column_name,data_type,data_length
7 from user_tab_columns
8 where table_name = 'T2'
9 )
10 UNION ALL
11 (
12 select 'IN T2, NOT T1', column_name,data_type,data_length
13 from user_tab_columns
14 where table_name = 'T2'
15 MINUS
16 select 'IN T2, NOT T1', column_name,data_type,data_length
17 from user_tab_columns
18 where table_name = 'T1'
19 )
20 /
'INT1,NOTT2' COLUMN_NAME DATA_TYPE DATA_LENGTH
------------- ------------------------------ ---------- -----------
IN T1, NOT T2 ENAME VARCHAR2 10
IN T1, NOT T2 JOB VARCHAR2 9
IN T2, NOT T1 JOB VARCHAR2 10
scott@ORA817.US.ORACLE.COM>
===============================================================
20)How to find out department wise second maximum salary.
select distinct d1.deptno, e1.sal
from emp e1, dept d1
where 2 = (select count(distinct e2.sal)
from emp e2, dept d2
where e2.sal >= e1.sal
and d2.deptno = e2.deptno
and d1.deptno = d2.deptno)
and d1.deptno = e1.deptno
=================================
21) In a cursor going we have 10 records now i want go to exactly for only 5th record.is it possible??
Ans:-
Yes, It is possible u can use the rowcount after fethchin
Declare
cursor cur_t is select * from t4;
rec_t t4%rowtype;
i number(2);
begin
open cur_t;
for i in 1..10
LOOP
fetch cur_t into rec_t;
if cur_t%rowcount in (5) --or IF i in(5) also we can use
then
dbms_output.put_line('no: ' || rec_t.no || ', name: ' || rec_t.name);
end if;
end loop;
end;
=======================================================
Mutating table Example:-
-----------------
Example 1
Select in a mutating table from a row trigger (Tested on Oracle 8.1.7)
We want to explain this situation on an example. We have two tables "A" and "B". "A" is the master table and "B" the detail table. We specified a foreign key between "B" and "A" with the CASCADE DELETE option.
Here are the CREATE statements
drop table B;
drop table A;
create table A (
ida number not null,
vala varchar2(10),
primary key(ida));
create table B (
idb number,
valb varchar2(10),
foreign key (idb) references A (ida) on delete cascade)
/
create or replace trigger b_br
after delete on B
for each row
declare
n integer;
begin
select count(*) into n from A;
dbms_output.put_line('there are ' || n || ' rows in A');
dbms_output.put_line('after statment on B');
dbms_output.new_line;
end;
/
insert into A values(1,'Table A');
insert into A values(2,'Table A');
insert into B values(1,'Table B');
insert into B values(1,'Table B');
commit;
set serveroutput on;
delete from A where idA = 1;
ERROR at line 1:
ORA-04091: table SCOTT.A is mutating, trigger/function may not see
ORA-06512: at "SCOTT.B_BR", line 4
ORA-04088: error during execution of trigger 'SCOTT.B_BR'
1) Retrive the last 10 rows from a table
select rownum from emp
group by rownum
having rownum >=(select max(rownum)-10 from emp)
(or)
select * from (select rownum a, CLASS_CODE,CLASS_DESC from clm)
where a > ( select (max(rownum)-10) from clm)
2) How to Retrive the Duplicate rows from a table
SELECT <COLUMN_NAME> , COUNT(*) FROM TABLE.NAME
GROUP BY <COLUMN_NAME>
HAVING COUNT(*) > 1
3) Department wise 2nd heighest Salary
select distinct d1.deptno, e1.sal
from emp e1, dept d1
where 2 = (select count(distinct e2.sal)
from emp e2, dept d2
where e2.sal >= e1.sal
and d2.deptno = e2.deptno
and d1.deptno = d2.deptno)
and d1.deptno = e1.deptno
===================================================
Select max(e1.sal),e1.deptno
from emp e1
where sal <=(select max(sal)
from emp e2
where e2.deptno = e1.deptno)
group by e1.deptno
Hewitt Associates(26-JUN-07):-
==============================
1)To get the balance based on DRCR
select SUM(DECODE(DRCR,'C',amount,0))-SUM(DECODE(DRCR,'D',amount,0)) from account
2)
Column
=========
3
2
1
A001
A002
A003
1001
1002
1003
Using the Order by Whats the Order will come
Answer is
SNO -->VARCHAR2 field
----
1
1000
1001
2
3
A001
A002
A003
a004
a200
It will Give the Assending/desending Order Based on Ascii Value...
Inline View:-
===============
SELECT ename,deptno
FROM (SELECT ename,deptno
FROM emp)a
(SELECT deptno
FROM emp)b
WHERE a.deptno = b.deptno
--->select sal,sum(sal) over (order by sal) TOTALSALARY from salary;
SAL TOTALSALARY
---------- -----------
1000 1000
2000 3000
3000 6000
4000 10000
checking that the string does not contain any special character
SELECT NVL(LENGTH(LTRIM(RTRIM(TRANSLATE('RAGHA **NDRA','ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_',' ')))), 0)
FROM DUAL;
other way:
op_type1 := replace(:blk_cgtm_op_type.op_type,' ','*');
FOR i IN 1 .. length(op_type1)
LOOP
op_char := ASCII(SUBSTR(op_type1,i,1));
IF OP_CHAR not BETWEEN 48 AND 57
and OP_CHAR not BETWEEN 65 AND 90
and OP_CHAR not BETWEEN 97 AND 122
then
l_found := 1;
end if;
END LOOP;
IF L_FOUND = 1
THEN
alert_return := ovpkcs.fn_dispmsg('CG-MNT18',';', ';');
Raise FORM_TRIGGER_FAILURE;
end if;
*********************************
Wednesday, 14 September 2011
Various Cursor Attributes
SQL%FOUND: Boolean attribute that evaluates to TRUE if most recent SQL statement affects one or more rows.
SQL%NOTFOUND: Boolean attribute that evaluates to TRUE if most recent SQL statement does not affect any row.
SQL%ISOPEN: Always evaluates to FALSE because P/L SQL closes implicit cursors immediately after they are executed.
Various Block Co-ordination Properties
a) Immediate
Default Setting. The Detail records are shown when the Master Record are shown.
b) Deffered with Auto Query
Oracle Forms defer fetching the detail records until the operator navigates to the detail block.
c) Deferred with No Auto Query
The operator must navigate to the detail block and explicitly execute a query
Types of Triggers in Forms
Interface event triggers: - Interface event triggers fire in response to events that occur in the form interface. Some of these trigger, such as When-Button-Pressed, fire only in response to operator input or manipulation. Others, like When-Window-Activated, can fire in response to both operator input and programmatic control. E.g. When-Button-Pressed, When-Checkbox-Changed, Key- [all], When-Radio-Changed, When-Timer-Expired, When-Window-Activated, When-Window-Resized
Master-detail triggers: - Form Builder generates master-detail triggers automatically when you define a master-detail relation between blocks. The default master-detail triggers enforce coordination between records in a detail block and the master record in a master block. Unless you are developing your own custom block-coordination scheme, you do not need to define these triggers yourself. Instead, simply create a relation object, and let Form Builder generate the triggers required to manage coordination between the master and detail blocks in the relation. E.g. On-Check-Delete-Master, On-Clear-Details, On-Populate-Details
Message-handling triggers: - Form Builder automatically issues appropriate error and informational messages in response to runtime events. Message handling triggers fire in response to these default messaging events. E.g. On-Error, On-Message
Navigational triggers: - Navigational triggers fire in response to navigational events. For instance, when the operator clicks on a text item in another block, navigational events occur as Form Builder moves the input focus from the current item to the target item. Navigational events occur at different levels of the Form Builder object hierarchy (Form, Block, Record, Item). Navigational triggers can be further sub-divided into two categories: Pre- and Post- triggers, and When-New-Instance triggers. Pre- and Post- triggers fire as Form Builder navigates internally through different levels of the object hierarchy. As you might expect, these triggers fire in response to navigation initiated by an operator, such as pressing the [Next Item] key. However, be aware that these triggers also fire in response to internal navigation that Form Builder performs during default processing. To avoid unexpected results, you must consider such internal navigation when you use these triggers. E.g. Pre-Form, Pre-Block, Pre-Text-Item, Post-Text-Item, Post-Record, Post-Block, Post-Form
When-New-Instance triggers fire at the end of a navigational sequence that places the input focus in a different item. Specifically, these triggers fire just after Form Builder moves the input focus to a different item, when the form returns to a quiet state to wait for operator input. Unlike the Pre- and Post- navigational triggers, the When-New-Instance triggers do not fire in response to internal navigational events that occur during default form processing. E.g. When-New-Form-Instance, When-New-Block-Instance, When-New-Record-Instance, When-New-Item-Instance
Query-time triggers: - Query-time triggers fire just before and just after the operator or the application executes a query in a block. E.g. Pre-Query, Post-Query
Transactional triggers: - Transactional triggers fire in response to a wide variety of events that occur as a form interacts with the data source. E.g. On-Delete, On-Insert, On-Lock, On-Logon, On-Update, Post-Database-Commit, Post-Delete, Post-Forms-Commit, Post-Insert, Post-Update, Pre-Commit, Pre-Delete, Pre-Insert, Pre-Update
Validation triggers: - Validation triggers fire when Form Builder validates data in an item or record. Form Builder performs validation checks during navigation that occurs in response to operator input, programmatic control, or default processing, such as a Commit operation. E.g. When-Validate-Item, When-Validate-Record
delete abc a where a.rowid < (Select Max(b.rowid) from abc b where a.a=b.a and a.b=b.b);
select sal,sum(sal) over (order by sal) CumTot from salary;
Types of Canvases
Stack Canvas [you can display more then one stack canvas in a window at the same time]
Tab Type Window [In Tab canvas that have tab pages and have one or more then tab page]
Toolbar Canvas [A toolbar canvas often is used to create Toolbar Windows. There are two type of Toolbar window.
Horizontal Toolbar Canvas: - Horizontal Toolbar canvases are displayed at the top of the window, Just under the Main Menu Bar.
Vertical Toolbar Canvas: - While vertical Toolbar are displayed along the Left Edge of the window.
Static & Dynamic LOV
Sequence of Trigger Fire while Committing
? Pre Commit
? Pre/On/Post Delete
? Pre/On/Post Update
? Pre/On/Post Insert
? On commit
? Post Database Commit
ROWCOUNT in cursor FOR loop Sure, for all the good it will do you
How do I access the %ROWCOUNT for an implicit cursor in a cursor FOR loop, as in (select * from dept) loop?
Answer:
Raymond, if you want to get information about the status of your cursor inside a cursor FOR loop, you should NOT use an implicit cursor within the loop statement, as you suggest in your question. In other words, if I worked with a table defined as follows:
CREATE TABLE question (
title VARCHAR2(100),
description VARCHAR2(2000));
INSERT INTO question VALUES ('Use implicit?',
'How can I access SQL% cursor attributes inside a cursor FOR loop
with an implicit cursor');
INSERT INTO question VALUES ('Use explicit?',
'How can I access cursor attributes inside a cursor FOR loop
with an explicit cursor?');
then I would write code like this:
DECLARE
CURSOR question_cur
IS
SELECT *
FROM question;
BEGIN
FOR rec IN question_cur
LOOP
DBMS_OUTPUT.put_line (question_cur%ROWCOUNT);
END LOOP;
END;
/
You can, in fact, reference SQL%ROWCOUNT inside a cursor FOR loop built around an implicit cursor, but it turns out that the SQL% cursor attributes are not changed by the actions of a implicit-based cursor FOR loop. Check out the rowcount.sql script to see a demonstration of this behavior.
And if you don't really need to obtain attribute information for each row fetched, you are even better off using a BULK COLLECT, as in:
DECLARE
TYPE question_tc IS TABLE OF question%ROWTYPE
INDEX BY PLS_INTEGER;
l_questions question_tc;
BEGIN
SELECT *
BULK COLLECT INTO l_questions FROM question;
DBMS_OUTPUT.put_line (SQL%ROWCOUNT);
DBMS_OUTPUT.put_line (l_questions.COUNT);
END;
Report Level Triggers (Sequence)
• After parameter form
• Before Report
• Between Pages
. After Report
Property Class & Visual Attributes
Visual attributes are the font, color, and pattern properties that you set for form and menu objects that appear in your application's interface. Visual attributes can include the following properties: Font properties, Color and pattern properties. Every interface object has a Visual Attribute Group property that determines how the object's individual visual attribute settings (Font Size, Foreground Color, etc.) are derived
Named visual attributes define only font, color, and pattern attributes; property classes can contain these and any other properties.
You can change the appearance of objects at runtime by changing the named visual attribute programmatically; property class assignment cannot be changed programmatically.
When an object is inheriting from both a property class and a named visual attribute, the named visual attribute settings take precedence, and any visual attribute properties in the class are ignored.
Property Class has triggers and Visual Attributes don't have same.
PL SQL Tables Arrays
Rules for PL/SQL Tables:
A loop must be used to insert values into a PL/SQL Table
You cannot use the Delete command to delete the contents of PL/SQL Table. You must assign an empty table to the PL/SQL table being deleted.
Object Libraries
Object Library can be used to:
Create, store, maintain, and distribute standard and reusable objects.
Rapidly create applications by dragging and dropping predefined objects to your form.
There are several advantages to using object libraries to develop applications:
Object libraries are automatically re-opened when you startup Form Builder, making your reusable objects immediately accessible.
You can associate multiple object libraries with an application. For example, you can create an object library specifically for corporate standards, and you can create an object library to satisfy project-specific requirements.
Object libraries feature Smart Classes-- objects that you define as being the standard. You use Smart Classes to convert objects to standard objects.
Object Groups
Object groups provide a way to bundle objects into higher-level building blocks that can be used in other parts of an application and in subsequent development projects. For example, you might build an appointment scheduler in a form and then decide to make it available from other forms in your applications. The scheduler would probably be built from several types of objects, including a window and canvas, blocks, and items that display dates and appointments, and triggers that contain the logic for scheduling and other functionality. If you packaged these objects into an object group, you could then copy them to any number of other forms in one simple operation.
You can create object groups in form and menu modules. Once you create an object group, you can add and remove objects to it as desired.
Normalization De-Normalization
1. Eliminate Repeating Groups - Make a separate table for each set of related attributes, and give each table a primary key.
2. Eliminate Redundant Data - If an attribute depends on only part of a multi-valued key, remove it to a separate table.
3. Eliminate Columns Not Dependent On Key - If attributes do not contribute to a description of the key, remove them to a separate table.
4. Isolate Independent Multiple Relationships - No table may contain two or more 1:n or n:m relationships that are not directly related.
5. Isolate Semantically Related Multiple Relationships - There may be practical constrains on information that justify separating logically related many-to-many relationships.
1st Normal Form (1NF)
Def: A table (relation) is in 1NF if
1. There are no duplicated rows in the table.
2. Each cell is single-valued (i.e., there are no repeating groups or arrays).
3. Entries in a column (attribute, field) are of the same kind.
Note: The order of the rows is immaterial; the order of the columns is immaterial.
Note: The requirement that there be no duplicated rows in the table means that the table has a key (although the key might be made up of more than one column—even, possibly, of all the columns).
2nd Normal Form (2NF)
Def: A table is in 2NF if it is in 1NF and if all non-key attributes are dependent on all of the key.
Note: Since a partial dependency occurs when a non-key attribute is dependent on only a part of the (composite) key, the definition of 2NF is sometimes phrased as, "A table is in 2NF if it is in 1NF and if it has no partial dependencies."
3rd Normal Form (3NF)
Def: A table is in 3NF if it is in 2NF and if it has no transitive dependencies.
Boyce-Codd Normal Form (BCNF)
Def: A table is in BCNF if it is in 3NF and if every determinant is a candidate key.
4th Normal Form (4NF)
Def: A table is in 4NF if it is in BCNF and if it has no multi-valued dependencies.
5th Normal Form (5NF)
Def: A table is in 5NF, also called "Projection-Join Normal Form" (PJNF), if it is in 4NF and if every join dependency in the table is a consequence of the candidate keys of the table.
Domain-Key Normal Form (DKNF)
Def: A table is in DKNF if every constraint on the table is a logical consequence of the definition of keys and domains.
De-Normalization:
De-normalization is a technique to move from higher to lower normal forms of database modeling in order to speed up database access. You may apply De-normalization in the process of deriving a physical data model from a logical form.
Example for Normalization
The Daisy Hill Puppy farm currently has the following data items for puppies:
Puppy Number
+ Puppy Name
+ Kennel Code
+ Kennel Name
+ Kennel Location
+ { Trick ID
+ Trick Name
+ Trick Where Learned
+ Skill Level
}1...n
When the file was first set up, it was thought that no puppy could possibly learn more than 10 tricks before graduation, but one puppy, Snoopy, learned more than 40 tricks before his adoption by Charles Brown. This forced a restructuring of the entire file, but it also left most of the file filled with meaningless spaces since the average puppy learned only three of the forty possible tricks. In addition, more and more people are asking for puppies, which know specific tricks. Right now the entire file of 25,693 puppies needs to be searched to find a match.
1NF -- Eliminate Repeating Groups
Make a separate table for each set of related attribute, and give each table a primary key. How?
Split the table into two tables:
Puppy Table = Puppy Number
+ Puppy Name
+ Kennel Code
+ Kennel Name
+ Kennel Location
Trick Table = Puppy Number + Trick ID
+ Trick Name
+ Trick Where Learned
+ Skill Level
It would help to have all the trick data to be in a separate table. This would decrease the table size, since every puppy who knows trick 43 would have its name, Roll Over, too. If the last puppy to know trick 43 were run over by a car, his record will be removed and we will lose all knowledge of trick 43.
2NF -- Eliminate Redundant Data
If an attribute depends on only part of a multi-valued key, remove it into a separate table. How?
Split the Trick Table into two: Tricks and Puppy Tricks.
Tricks = Trick ID
+ Trick Name
Puppy Tricks = Puppy Number + Trick ID
+ Trick Where Learned
+ Skill Level
Puppy Table = Puppy Number
+ Puppy Name
+ Kennel Code
+ Kennel Name
+ Kennel Location
Now suppose no puppies from the K9-Kennel were currently stored in the database. There then remains no record of K9-Kennel's existence!
3NF -- Not Dependent On Key
If attributes do not contribute to a description of the key, remove them to a separate table. How?
Split Puppy Table into two tables: Puppies and Kennels
Tricks = Trick ID
+ Trick Name
Puppy Tricks = Puppy Number + Trick ID
+ Trick Where Learned
+ Skill Level
Puppies = Puppy Number
+ Puppy Name
+ Kennel Code
Kennels = Kennel Code
+ Kennel Name
+ Kennel Location
Suppose we want to add a new attribute to the Puppy-Trick table, "Costume." This way we can find puppies who can "sit-up- and-beg" while wearing a Ted Turner mask. The two need not relate, for example, a puppy may be able to walk upright while wearing a wet suit, but may not be able to do both at the same time. The new Puppy Tricks table will look like this:
Puppy Tricks = Puppy Number + Trick ID + Costume
+ Trick Where Learned
+ Skill Level
4NF -- Isolate Independent Multiple Relationships
No table may contain two or more 1:n or n:m relationships that are not directly related. Here Puppy Number specifies a well-defined set of Trick IDs and well-defined sets of costumes. Thus there is multi-dependency. How do we prevent anomalies in this case?
Split Puppy Tricks in two, Puppy Tricks and Puppy Costumes.
Puppy Tricks = Puppy Number + Trick ID
+ Trick Where Learned
+ Skill Level
Puppy Costumes = Puppy Number + Costume
Normalization and Normal Forms Example
Example Table "company", not normalized:
Company
Attribute
Name John Walker Jim Bim
Pers.ID 1 1
Dept. No. 1 2
Dept. Name Europe USA
Project No. 5, 7, 8 5, 8
Project Name Soap, Pasta, OliveOil Soap, OliveOil
Job in Project Analysis, Leader, Marketing Leader, Leader
Salary/h 13, 18, 15 18, 18
First NF (1NF): A relation cannot have repeating fields or groups (no field must have more than one value):
Employees
Attribute
Name John Walker Jim Bim
Pers. ID 1 1
Dept. No. 1 2
Dept. Name Europe USA
Projects
Attribute
Project No. 5 7 8
Project Name Soap Pasta OliveOil
Project Assignment
Attribute
Project No. 5 5 7 8 8
Pers. ID 1 1 1 1 1
Dept. No. 1 2 1 1 2
Job in Project Analysis Leader Leader Marketing Leader
Salary/h 13 18 18 15 18
Second NF (2NF): 1NF + every non-key field must be functionally dependent on all of the key.
Here: In the relation "Employees" the "Dept. Name" depends only on the "Dept. No." but not on "Pers. ID", thus not on all parts of the key:
Employees
Attribute
Name John Walker Jim Bim
Pers. ID 1 1
Dept. No. 1 2
Departments
Attribute
Dept. No. 1 2
Dept. Name Europe USA
The relations "Projects" and "Project Assignment" can remain as they are:
Projects
Attribute
Project No. 5 7 8
Project Name Soap Pasta OliveOil
Project Assignment
Attribute
Project No. 5 5 7 8 8
Pers. ID 1 1 1 1 1
Dept. No. 1 2 1 1 2
Job in Project Analysis Leader Leader Marketing Leader
Salary/h 13 18 18 15 18
________________________________________
Third NF (3NF): There must be no transitive dependency that is an attribute depends on one or more other non-key attributes.
Here: The relations "Employees", "Depends" and "Projects" can remain as they are.
But in "Projects Assignment" the salary depend only on the job, thus only indirectly on the key. This is a transitive dependency. We have to add a "Payment" relation.
Employees
Attribute
Name John Walker Jim Bim
Pers. ID 1 1
Dept. No. 1 2
Departments
Attribute
Dept. No. 1 2
Dept. Name Europe USA
Projects
Attribute
Project No. 5 7 8
Project Name Soap Pasta OliveOil
Payment
Attribute
Job Analysis Marketing Leader
Salary/h 13 15 18
Project Assignment
Attribute
Project No. 5 5 7 8 8
Pers. ID 1 1 1 1 1
Dept. No. 1 2 1 1 2
Job in Project Analysis Leader Leader Marketing Leader
Note: We could add an"Assignment No." in the "Project Assignment" relation as new key to avoid having only key attributes.
Now the DB is in 3NF: No Data-field modification should necessitate any other "follow-up" adjustment in any other data-field, because of transitive dependencies
ModelModeless Windows (Difference)
You can display multiple modeless windows at the same time, and end users can navigate freely among them. Modeless windows remain displayed until they are dismissed by the end user or hidden programmatically. You can set the Hide on Exit property for a modeless window to specify whether it should remain displayed when the end user navigates to another window. Modal windows are usually used as dialogs, and have restricted functionality compared to modeless windows. On some platforms, modal windows are "always-on-top" windows that cannot be layered behind modeless windows. The Hide on Exit property does not apply to modal windows. Modal dialog windows cannot have scroll bars
Matrix Reports (Matrix By Groups)
To create a matrix report, you need at least four groups: one group must be a cross-product group, two of the groups must be within the cross-product group to furnish the "labels," and at least one group must provide the information to fill the cells. The groups can belong to a single query or to multiple queries.
A matrix with group report is a group above report with a separate matrix for each value of the master group.
A nested matrix (crosstab) report is a matrix report in which at least one parent/child relationship appears within the matrix grid.
The new Child Dimension property of the nested group enables you to eliminate empty rows and/or columns in your single-query nested matrix.
Types of Matrix Reports
Simple Matrix Report: Is a matrix with only two dimensions
Nested Matrix Report: Has multiple dimensions going across and/or down the page
Multi-Query Matrix with Break: Is similar to a nested matrix report in that it has more than two dimensions. Does not display records that do not contain data
Matrix Break Reports: Contains a new matrix for each master record
Master-Detail Relation
On-Check-Delete-Master: - Fires when Form Builder attempts to delete a record
in a block that is a master block in a master-detail relation.
On-Clear-Details: - Fires when Form Builder needs to clear records in a block
that is a detail block in a master-detail relation because those records no longer
correspond to the current record in the master block.
On-Populate-Details: - Fires when Form Builder needs to fetch records into a block that is the detail block in a master-detail relation so that detail records are synchronized with the current record in the master block.
(i) Isolated: - Masters Can be deleted when Child is existing
Triggers: - On Populate details Block
On Clear Details Form
Procedure
Check Package Failure
Clear all master Detail
Query Master Detail
(ii) Non- Isolated: - Masters cannot be deleted when Child is existing.
Triggers: - On Populate details Block
On Check Delete master Block
On Clear Details Form
Procedure
Check Package Failure
Clear all master Detail
Query Master Detail
(iii) Cascading: - Child Record Automatically Deleted when Masters is deleted.
Triggers: - On Populate details Block
Pre Delete Block
On Clear Details Form
Procedure
Check Package Failure
Clear all master Detail
Query Master Detail