· To simplify the maintenance of the data through updates, insertions, and deletion
· To reduce the need to restructure or reorganize data when new application requirements arise. · Normalization can improve the quality of design for an application.
There are totally Five Normal Forms(Rules) out of which, any database should necessarily satisfy
three of them, those Three Normal Forms are as follows:
First normal form is achieved when all repeating groups are removed so that a record is of fixed length. A repeating group, the re-occurrence of a data item within a record, is actually
another relation. Hence, it is removed from the record and treated as an additional record structure,
or relation.
Second Normal form should be in first normal form and no partial dependency exists. Means if we have a composite primary key(combination of 2 or more fields) then all the non keys
must depend on the composite primary key. no attribute should depend upon the part of key.(for
example if Rollno and SSno is a composite key, then no other field in that particular table should
be depedent upon either Rollno or ssno individually)
Third Normal form is achieved when Transitive Dependencies are removed from a record design.
The general case is as follows :
A,B and C are three data items in a record. If C is functionally dependent on B (2nd N.F) and
B is functionally dependent on A Then C is functionally dependent on A Therefore, a Transitive
Dependency exists. In data management, transitive dependency is a concern because data can inadvertently be lost when the relationship is hidden. In the general case above, if A is deleted, then B and C are
deleted also, whether or not this is intended. This problem is eliminated by designing the record
for third normal form. Conversion to third normal form removes the transitive dependency by
splitting the relation into two separate relations.
BCNF must be 3NF and every determinant is a candidate key. Candidate key is other than primary key, which uniquely identify each row in the table.
for example ssno is PK then rollno becomes Candidate key.
4NF and 5NF are depends on instance. we can not give a proper def. bcz it all depends on joins. "CODD's 12 RULES" for a fully Relational DBMS
INTRODUCTION According to Elmasri and Navathe (1994), Dr. E. F. Codd, the originator of the relational data model, published a two-part article in ComputerWorld (Codd, 1985) that lists 12 rules for
how to determine whether a DBMS is relational and to what extent it is relational. These rules
provide a very useful yardstick for evaluating a relational system. Codd also mentions that,
THE 12 RULES
Rule 1: The Information Rule All information in a relational database is represented explicitly at the logical level in exactly one way by values in tables. All data is represented in the form of relations/tables (with rows and columns)Simple Consistent and versatile
Rule 2: Guaranteed Access Rule Each and every datum (atomic value) in a relational database is guaranteed to be logically accessible by resorting to a table name, primary key value, and column name. All Data is uniquely
identified and accessible via this identity.
Rule 3: Systematic Treatment of Null Values Null values (distinct from empty character string or a string of blank characters and distinct from zero or any other number) are supported in the fully relational DBMS for representing
missing information in a systematic way, independent of data type.
Rule 4: Dynamic On-line Catalog based on the Relational Model The database description is represented at the logical level in the same way as ordinary data, so authorized users can apply the same relational language to its interrogation as they apply
to regular data.
Rule 5: Comprehensive Data Sublanguage Rule A relational system may support several languages and various modes of terminal use (for example, the fill-in-blanks mode). However, there must be at least one language whose statements
are expressible, per some well-defined syntax, as character strings and whose ability to support all
of the following is comprehensible: data definition, view definition, data manipulation (interactive
and by program), integrity constraints, and transaction boundaries (begin, commit, and rollback).
Rule 6: View Updating Rule All views that are theoretically updateable are also updateable by the system. Views are virtual tables. They appear to behave as conventional tables except that they are built
dynamically when the query is run. This means that a view is always up to date. It is not always
theoretically possible to update views. One problem exists when a view relates to part of a table
not including a candidate key. This means that potential updates would violate the entity integrity
rule.
Rule 7: High-level Insert, Update, and Delete The capability of handling a base relation or a derived relation as a single operand applies not only to the retrieval of data but also to the insertion, update, and deletion of data. i.e. The user
should be allowed to Delete, Update a set of tuples (rather than row by row)
Rule 8: Physical Data Independence Application programs and terminal activities remain logically unimpaired whenever any changes are made in either storage representation or access methods. i.e. Users and programs are
not dependent on the physical structure of the database.
Rule 9: Logical Data Independence Application programs and terminal activities remain logically unimpaired when information-preserving changes of any kind that theoretically permit unimpairment are made to
the base tables. Users and Programs are independent of the logical structure of the database, i.e.
the logical structure of the data can evolve with minimal impact on the programs.
Rule 10: Integrity Independence Integrity constraints specific to a particular relational database must be definable in the relational data sublanguage and storable in the catalog, not in the application programs. A
minimum of the following two integrity constraints must be supported:
1. Entity integrity: No component of a primary key is allowed to have a null value.
2. Referential integrity: For each distinct non-null foreign key value in a relational database,
there must exist a matching primary key value from the same domain.
Rule 11: Distribution Independence A relational DBMS has distribution independence. Distribution independence implies that users should not have to be aware of whether a database is distributed. Applications should still
work in a distributed database (DDB).
Rule 12: Nonsubversion Rule If a relational system has a low-level (single-record-at-a-time) language, that low-level language cannot be used to subvert or bypass the integrity rules or constraints expressed in the
higher-level (multiple-records-at-a-time) relational language. If there is a record at a time interface (e.g. via 3GL), Security and integrity of the database must no be violated. There should be no backdoor to bypass the security imposed by the DBMS.
On the basis of the above rules, there is no fully relational DBMS available today.
Questions and Answers :
What is Pseudo Colomn ? USER, UID, SYSDATE, ROWNUM, ROWID, NULL, AND LEVEL
How to Display output in PL/SQL ?
we first set serveroutput on at SQL Prompt. and then in sql programming we specify as dbms_output.put_line(`hdjhd' || `sakdha'); No Displays are allowed in PL/SQL programming with select statement
Write about Commands and Keywords ? Alter : ALTER TABLE EMP ADD .......... , MODIFY .......... ;
for a in 1..10 loop ........... end loop;
loop exit when a<1 .................. end loop;
while ..... loop.................end loop;
Data Types : number, integer, varchar2, char, date, Boolean;
goto procedure name;..............<
exit, rollback, commit, savepoint. References: This keyword is used to refer two similar fields of different tables.
What are different built in functions ? CONCATENATE, INITCAP, LENGTH, LOWER, UPPER, LPAD, RPAD, LTRIM (removes the character specified left side of word), RTRIM, SUBSTR (displays values from
specified location onwards), TRANSLATE (for single character), REPLACE (for more than one
character ),CHR ( prints character of given ASCII value), ASCII (value of given character ). ABS, CEIL, FLOOR, SQRT, POWER, SIGN, TRUNC, ROUND, EXP, MOD, LOG, LN, GREATEST, LEAST, SYSDATE, ADD_MONTHS, MONTHS_BETWEEN.
what are emp.sal%type and emp%rowtype ?
First one is to assign a variable of type sal only.
Second is to assign a complete row of type emp table.
What are constraints ? Constraint Clause : This will constrain a single column or a group of columns in a table. and are used for maintaining integrity of the database.
Different Constraints are : candidate keys, primary keys, foreign keys, check conditions.
Can specify as a part of column definition, or at the end of the table (if more than one column). Check Constraint : for validations to fields.
Naming Constraint (table constraints): Can name the constraint else system will name it by default.
Different types of joins ? Equi join : where emp.deptno = dept.deptno;
Non Equi join : where e.sal >= g.losal;
Outer join :***********e.deptno(+)=d.deptno;
Different types of Keys ? Foreign Key : This is a referential integrity constraint and specifies the values of primary key in other table. and is mentioned as :
DEPTNO number(2) REFERENCES DEPT(DEPTNO); The clause ON DELETE CASCADE added to REFERENCES clause tells Oracle to delete the
dependent rows when we delete the row in the parent table. Unique Key : If declared, then does not accept duplicate and also NULL values. And can have many Unique key fields. Primary Key : Similar to Unique key but, also maintains an index on primary key and also used to connect two tables.
Write about cursors ? Implicit (SQL is implicit by default ) and Explicit cursors. EXIT WHEN C1%NOTFOUND, IF C1%FOUND THEN, IF C1%ISOPEN THEN,
FOR LOOP in CURSOR will : 1) open the cursor. 2) fetches the records from cursor one by one. 3) keeps the track of number of records in the cursor.
Super Dynamism in Cursors is obtained by passing the values as parameters( ie pass by value)
ie., for x in c1(a,b) Multiple Cursors : These are nothing but nested cursors........... In Implicit Cursors there is no need of declaration of cursors, by default system will create a cursor whenever a query is written...and the conditions are like if SQL%NOTFOUND
if SQL%ROWCOUNT > 2 will keep a count of the number of records updated.
SQL is a keyword and cannot be used to name as a cursor name explicitly.
Difference between group functions and single row functions ?
Group Function Single Row Function A group function operates A single row function on many rows returns one and result for one row. returns single result.
Not allowed in Pl/sql procedural Allowed in Pl/Sql Procedural statements
eg SUM(),AVG,MIN,MAX etc eg UPPER,LOWER,CHR...
Difference between DECODE and TRANSLATE ?
DECODE is value by value TRANSLATE is character by character replacement. replacement. Ex SELECT DECODE('ABC','A',1,'B',2,'ABC',3) eg SELECT
from dual; o/p 3 TRANSLATE('ABCGH', 'ABCDEFGHIJ', 1234567899) FROM DUAL; o/p 12378 (DECODE command is used to bring IF,THEN,ELSE logic to SQL.It tests for the IF values(s) and
then aplies THEN value(s) when true, the ELSE value(s) if not.)
Difference between TRUNCATE and DELETE ? TRUNCATE deletes much faster than DELETE
Truncate Delete It is a DDL statement It is a DML statement It is a one way trip,cannot One can Rollback ROLLBACK
Doesn't have selective features (where clause) Has Doesn't fire database triggers Does It requires disabling of referential Does not require constraints.
What is a CO-RELATED SUBQUERY ?
A CO-RELATED SUBQUERY is one that has a correlation name as table or view designator in
the FROM clause of the outer query and the same correlation name as a qualifier of a search
condition in the WHERE clause of the subquery.
eg SELECT field1 from table1 X WHERE field2>(select avg(field2) from table1 Y
where field1=X.field1);
(The subquery in a correlated subquery is revaluated for every row of the table or view named in the outer query.) What are various joins used while writing SUBQUERIES ? Self join-Its a join foreign key of a table references the same table.
Outer Join--Its a join condition used where One can query all the rows of one of the
tables in the join condition even though they don't satisfy the join condition.
Equi-join--Its a join condition that retrieves rows from one or more tables in which one
or more columns in one table are equal to one or more columns in the second table.
What are various constraints used in SQL ? NULL, NOT NULL, CHECK, DEFAULT
What are different Oracle database objects ? TABLES, VIEWS, INDEXES, SYNONYMS, SEQUENCES, TABLESPACES etc
What is difference between Rename and Alias ? Rename is a permanent name given to a table or column whereas Alias is a temporary name given to a table or column which do not exist once the SQL statement is executed.
What is a view ? A view is stored procedure based on one or more tables, it's a virtual table.
What are various privileges that a user can grant to another user ? SELECT, CONNECT, RESOURCES
What is difference between UNIQUE and PRIMARY KEY constraints ? A table can have only one PRIMARY KEY whereas there can be any number of UNIQUE keys. The columns that compose PK are automatically define NOT NULL, whereas a column that
compose a UNIQUE is not automatically defined to be mandatory must also specify the column is
NOT NULL.
Can a primary key contain more than one columns ? Yes
How you will avoid duplicating records in a query ?
By using DISTINCT
What is difference between SQL and SQL*PLUS ? SQL*PLUS is a command line tool where as SQL and PL/SQL language interface and reporting tool. Its a command line tool that allows user to type SQL commands to be executed
directly against an Oracle database. SQL is a language used to query the relational
database(DML,DCL,DDL). SQL*PLUS commands are used to format query result, Set options,
Edit SQL commands and PL/SQL.
Which datatype is used for storing graphics and images ? LONG RAW data type is used for storing BLOB's (binary large objects).
How will you delete duplicating rows from a base table ?
DELETE FROM table_name A WHERE rowid>(SELECT min(rowid) from table_name B where B.table_no=A.table_no); CREATE TABLE new_table AS SELECT DISTINCT * FROM old_table; DROP old_table RENAME new_table TO old_table DELETE FROM table_name A
WHERE rowid NOT IN (SELECT MAX(ROWID) FROM table_name
GROUP BY column_name)
No comments:
Post a Comment