Sei sulla pagina 1di 7

What are the difference between DDL, DML

and DCL commands?



DDL

Data Definition Language (DDL) statements are used to define the database
structure or schema. Some examples:

CREATE - to create objects in the database
ALTER - alters the structure of the database
DROP - delete objects from the database
TRUNCATE - remove all records from a table, including all spaces allocated for
the records are removed
COMMENT - add comments to the data dictionary
RENAME - rename an object

DML

Data Manipulation Language (DML) statements are used for managing data within
schema objects. Some examples:

SELECT - retrieve data from the a database
INSERT - insert data into a table
UPDATE - updates existing data within a table
DELETE - deletes all records from a table, the space for the records remain
MERGE - UPSERT operation (insert or update)
CALL - call a PL/SQL or Java subprogram
EXPLAIN PLAN - explain access path to data
LOCK TABLE - control concurrency

DCL

Data Control Language (DCL) statements. Some examples:

GRANT - gives user's access privileges to database
REVOKE - withdraw access privileges given with the GRANT command

TCL

Transaction Control (TCL) statements are used to manage the changes made by
DML statements. It allows statements to be grouped together into logical
transactions.

COMMIT - save work done
SAVEPOINT - identify a point in a transaction to which you can later roll back
ROLLBACK - restore database to original since the last COMMIT
SET TRANSACTION - Change transaction options like isolation level and what
rollback segment to use
How many types of normal forms?

The formal classifications describing the level of database normalization in a data
model are called Normal Forms (NF) and the process of doing this is
Normalization.
First normal form

First normal form (1NF) lays the groundwork for an organised database design:
Ensure that each table has a primary key: minimal set of attributes which can
uniquely identify a record.
Eliminate repeating groups (categories of data which would seem to be required a
different number of times on different records) by defining keyed and non-keyed
attributes appropriately.
Atomicity: Each attribute must contain a single value, not a set of values.
'First normal form' depends on functional dependency formula f(x)=y. For every
value of x there is value for y.

Second normal form
Second normal form (2NF) If a table has a composite key, all attributes must be
related to the whole key:
The database must meet all the requirements of the first normal form.
The relational schema should not have any partial functional dependency i.e. No
proper subset of the primary key should derive a functional dependency belonging
to the same schema. For example, consider functional dependencies FD:{AB->C,
A->D, C->D} here AB is the primary key, as A->D this relational schema is not in
2NF.

Third normal form
Third normal form (3NF) requires that data stored in a table be dependent only on
the primary key, and not on any other field in the table.
The database must meet all the requirements of the first and second normal form.
All fields must be directly dependent on the primary key field. Any field which is
dependent on a non-key field which is in turn dependent on the Primary Key (ie a
transitive dependency) is moved out to a separate database table.
4 FOURTH AND FIFTH NORMAL FORMS
Fourth [5] and fifth [6] normal forms deal with multi-valued facts. The multi-
valued fact may correspond to a many-to-many relationship,
4.1 Fourth Normal Form
Under fourth normal form, a record type should not contain two or more
independent multi-valued facts about an entity. In addition, the record must satisfy
third normal form.
Fifth normal form deals with cases where information can be reconstructed from
smaller pieces of information that can be maintained with less redundancy. Second,
third, and fourth normal forms also serve this purpose, but fifth normal form
generalizes to cases not covered by the others.
Boyce-Codd normal form
Boyce-Codd normal form (or BCNF) requires that there be no non-trivial
functional dependencies of attributes on something other than a superset of a
candidate key (called a super key)
What is the diff b/w n++ & n+1

The expression n++ requires a single machine instruction such as INR to
carry out the increment operation whereas, n+1 requires more
instructions to carry out this operation.
If n+1 is executed,the value of n should be stored in memory,then bring
to CPU and perform addition in CPU and then write to memory
back.Hence,CPU time is consumed more.
Compilers nowadays are smarter,if it encounters n+1,it replaces it by
n++.Hence,it really doesn't matters for user since optimization is gained
by compiler.
Transactions and their properties
A transaction is a tool for distributed systems programming. It simplifies
failure scenarios. A transaction is a set of operations that transforms
data from one consistent state to another.
Transactions provide the ACID properties:
Atomicity. The changes in a transaction are atomic: either all
operations that are part of the transaction occur or none occurs.
Consistency. A transaction moves data between consistent states.
Isolation. Even though transactions can be executed concurrently,
no transaction sees another transaction's work in progress. The
transactions seem to run serially.
Durability. After a transaction completes successfully, its changes
survive subsequent failures.

Virtual function

In object-oriented programming, a virtual function or virtual method
is a function or method whose behavior can be overridden within an
inheriting class by a function with the same signature. This concept is a
very important part of the polymorphism portion of object-oriented
programming (OOP).
The concept of the virtual function solves the following problem:
In OOP when a derived class inherits from a base class, an object of the
derived class may be referred to (or cast) as either being the base class
type or the derived class type. If there are base class methods overridden
by the derived class, the method call behaviour is ambiguous.
The distinction between virtual and non-virtual resolves this ambiguity.
If the function in question is designated virtual in the base class then the
derived class's function would be called (if it exists). If it is not virtual,
the base class'
s function would be called.
Virtual functions overcome the problems with the type-field solution by
allowing the programmer to declare functions in a base class that can be
redefined in each derived class.
In C++, virtual methods are declared by prepending the virtual keyword
to the function's declaration
Abstract classes (C++ only)
An abstract class is a class that is designed to be specifically used as a base class.
An abstract class contains at least one pure virtual function. You declare a pure
virtual function by using a pure specifier (= 0) in the declaration of a virtual
member function in the class declaration.
The following is an example of an abstract class:
class AB {
public:
virtual void f() = 0;
};
Friend function
A friend function for a class is used in object-oriented programming to
allow access to public, private, or protected data in the class
from the outside.
[1]
Normally, a function that is not a member of a class
cannot access such information; neither can an external class.
Occasionally, such access will be advantageous for the programmer.
Under these circumstances, the function or external class can be declared
as a friend of the class using the friend keyword.
A friend function is declared by the class that is granting access. Friend
declaration can be placed anywhere in the class declaration. It is not
affected by the access control keywords.
A similar concept is that of friend class.
Friends should be used with caution. Too many functions or external
classes declared as friends of a class with protected or private data may
lessen the value of encapsulation of separate classes in object-oriented
programming and may indicate a problem in the overall architecture
design.

Potrebbero piacerti anche