Sei sulla pagina 1di 9

1. Compare SQL and PL/SQL.

Ans: SQL that is abbreviated from Structured Query Languages is a data oriented languagefor selecting and operating sets of data. SQL is commonly used by relational databasetechnologies such as Oracle, Microsoft Access, and Sybase etc. The term, PL/SQL is a proceduralextension of SQL. It is the Oracle native programming language that provides an edge to designdatabasecentric application. Both SQL and PL/SQL languages are designed with a commonpurpose, to access data within Oracle databases, but PL/SQL is designed to address thelimitation of SQL because it cannot be used to manipulate procedural programming withconditional, iterative and sequential statements. To work with PL/SQL, the users normallyinteract with an application that uses SQL to access a relational database on the back-end.SQL is widely popular as data oriented language for selecting and executing the sets of data. Itis differentiated from the PL/SQL in relation to its capability to create applications that may bethe source of data for your screens, web pages and reports while PL/SQL, known as aprocedural language, might be used to create format and display those screens, web page andreports that are designed with the help of SQL. It also acts as an application language like Javaor PHP can.The commands and instructions used in SQL aren t actually a part of the SQL standard but aresupported by the tools of SQL and are usually executed to assist format output like BREAK,BTITLE, COLUMN, PRINT or they are meant to create or store data/scripts. It also supports thecommands that directly interact with the database to perform the SHUTDOWN, CONNECT orCOPY actions. PL/SQL is also known as fourth-generation programming language because of itsability to support the data encapsulation, overloading, collection types, exceptions, andinformation hiding functions. PL/SQL also offers rapid prototyping and use variables and theirdeclarations, conditional controls like IF and CASE used in other programming languages like C,C++, Java, etc. It also uses looping structure such as LOOP, FOR LOOP and WHILE LOOP.Another advantage of using PL/SQL is its fast execution speed because it passes a block of statements to be executed to the server, whereas in SQL, only one statement is transferred tothe server at a time which is a time consuming process.Summary:SQL is a structured query language used for data manipulation, whereas PL/SQL is a procedurallanguage to design applications.PL/SQL is an application language usually used to build, format and display the user screens,web pages and reports, while SQL provides data for these applications.The user can embed SQL in a PL/SQL program or statement. But the vice versa is not possible.SQL is slower because it executes one statement at a time, while PL/SQL executes as a block of code.The core use of SQL is to code queries, data manipulation and development statements, butPL/SQL is broadly used to code program blocks, triggers, functions, etc.

2. Write a database trigger to implement the following check condition:  Given the following table: Empno Empname Joining Date

Every time the user enters the employee number in the above table, it should check that it is always >1 and < 200 .Ans: CREATE TABLE employee ( empno numeric(4), Empname varchar2(20), Joining_date date, CONSTRAINT check_empno CHECK (empno BETWEEN 1 and 200) );

3. Discuss the following types of Data Fragmentation Mechanisms:


Horizontal Data Fragmentation Derived Horizontal Fragmentation Vertical Fragmentation Mixed Fragmentation

Ans : The types of following Data Fragmentation Mechanisms are as follows:  Horizontal Fragmentation Horizontal Fragmentation consists of partitioning the tuples of a global relation into subsets;this is clearly useful in distributed databases, where each subset can contain data that havecommon geographical properties. It can be defined by expressing each fragment as a selectionoperation on the global relation. Example: let a global relation be

Then the horizontal fragmentation can be defined in the following way:


Now let us verify whether this fragmentation fulfills the conditions stated earlier. The completeness condition : If Manipal and Udupi are the only possible values of the CITY attribute, then it satisfies this condition. The reconstruction condition: can be verified easily, because it is always possible to reconstruct the SUPPLIER global relation through the following operation. SUPPLIER =SUPPLIER1 UN SUPPLIER2 The disjoint ness conditionis clearly verified. Qualification: The predicate, which is used in the selection operation and defines a fragment, iscalled as Qualification. For instance, in the above example the qualifications q1: CITY = Manipal q2: CITY = Udupi

We can generalize from the above example that in order to satisfy the completeness condition,the set of qualifications of all fragments must be complete, at least with respect to the set of allowed values. The reconstruction condition is always satisfied through the union operation, and the disjoint ness condition requires that qualifications be mutually exclusive.  Derived Horizontal Fragmentation This is a type of fragmentation, which is derived from the horizontal fragmentation of another relation. Example : Consider a global relation SUPPLY (SNUM, PNUM, DEPTNUM, QUAN) Where SNUM is a supplier number. If it is required that a fragment has to contain the tuples for suppliers, which are in a given city, and then we have to go for derived fragmentation. A semijoin operation with the fragments SUPLIER1 and SUPLIER2 is needed in order to determine the tuples of SUPPLY, which correspond to the suppliers in a given city. The derived fragmentation of SUPPLY can be therefore defined as follows: SUPPLY1= SUPPLY SJ SNUM=SNUM SUPPLIER1 SUPPLY 2= SUPPLY SJ SNUM=SNUM SUPPLIER2 The reconstruction of the global relation SUPPLY can be performed through the union operation as was shown for SUPPLIER. The completeness of the above fragmentation requires that there be no supplier numbers in the SUPPLY relation, which are not contained also in the SUPPLIER relation. This is a typical, and reasonable, integrity constraint for this database and usually is called as the Refer ential integrity constraint. The disjoint ness condition is satisfied if a tuple of the SUPPLY relation does not correspond to two tuples of the SUPPLIER relation that belong to two different fragments. In this case this condition is easily verified, because the supplier numbers are unique keys of the SUPPLIER relation.  Vertical Fragmentation The Vertical fragmentation of a global relation is the subdivision of its attributes into groups; fragments are obtained by Projecting the global relation over each group. This can be useful indistributed databases where each group of attributes can contain data that have commongeo graphical properties. The fragmentation is correct; if each attribute is mapped into at least one attribute of the fragments; moreover, it must be possible to reconstruct the original relation by joining the fragments together. Example: Consider a global relation EMP (EMPNUM, NAME, SAL, TAX, MGRNUM, DEPTNUM) A vertical fragmentation of this relation can be defines as EMP1=PJ EMPNUM,NAME, MGRNUM, DEPTNUM EMP

EMP2=PJ EMPNUM, SAL,TAX EMP The reconstruction of relation EMP can be obtained as EMP=EMP1 JNEMPNUM=EMPNUM EMP2 This is because; EMPNUM is a key of EMP. Let us draw some important points to be noted from this example. The purpose of including the key of the global relation into each fragment is to ensure there construction property. An alterative way to provide the reconstruction property is to generate tuple identifiers that are used as system-controlled keys. This can be convenient in order to avoid the replication of large keys; moreover, users cannot modify tuple identifiers. Let us finally consider the problem of fragment disjoint ness. First, we have seen that at leastthe key should be replicated in all fragments in order to allow reconstruction. In fact, if weinclude the same attribute in two different vertical fragments, we know exactly that the columnthat corresponds to this attribute. For example, consider the following vertical fragmentation of relation EMP: EMP1=PJ EMPNUM,NAME,MGRNUM,DEPTNUM EMP EMP2 = PJ EMPNUM,NAME,SAL,TAX EMP2 The attribute NAME is replicated in both fragments. We can remove this attribute when were construct relation EMP through an additional projection operation. EMP = EMP1 JN EMPNUM=EMPNUM PJ EMPNUM, SAL, TAX EMP2  Mixed Fragmentation The fragments that are obtained by the above fragmentation operations are relationsthemselves, so that it is possible to apply the fragmentation operations recursively, providedthat the correctness conditions are satisfied each time. The reconstruction can be obtained byapplying the reconstruction rules in reverse order. Example : Consider the same global relation

The following is a mixed fragmentation, which is obtained by applying the vertical fragmentation of the previous example, followed by a horizontal fragmentation on DEPTNUM:

The fragmentation tree of relation EMP

The reconstruction of relation EMP is defined by the following expression: EMP = UN (EMP1,EMP2, EMP3) JN EMPNUM=EMPNUM PJ EMPNUM, SAL, TAX EMP4 A fragmentation tree can conveniently represent mixed fragmentation (as shown in the above figure). In a fragmentation tree, the root corresponds to a global relation, the leaves corresponds to the leaves correspond to the fragments, and the intermediate nodes correspond to the intermediate results of the fragment-defining expressions. The EXAMPLE_DDB: The following codes shows the global and fragmentation schemata of EXAMPLE_DDB. Most of the global relations of EXAMPLE_DDB and their fragmentation have been already introduced. A DEPT relation, horizontally fragmented into three fragments on the value of the DEPTNUM attribute, is added. Global schema EMP ( EMPNUM, NAME, SAL, TAX, MGRNUM, DEPTNUM ) DEPT ( DEPTNUM, NAME, AREA, MGRNUM ) SUPPLIER ( S NUM , PNUM, DEPTNUM, QNUM )


4. How do you map the system table space with memory of database? Ans: Tablespace is a logical grouping of database objects, usually to facilitate security,performance, or the availability of database objects such as tables and indexes. A tablespace iscomposed of one or more datafiles on disk. A tablespace is the highest level of logical objects in the database. A database consists of one ormore tablespaces. A tablespace will frequently group together similar objects, such as tables,for a specific business area or a specific function. A particular tablespace can be reorganized,backed up, and so forth with minimal impact to other users whose data may be in othertablespaces. All Oracle databases must have at least one table space: the SYSTEM tablespace. Having morethan one tablespace is highly recommended when creating a database. In the figure 6.1 logicalstructures, you can see the SYSTEM table space and two others. A Database Block is the smallest unit of allocation in an Oracle database. One or more databaseblocks compose a database extent. At the other end of the spectrum of logical objects is the database block (also known as an Oracle block), the smallest unit of storage in an Oracledatabase. Every database block in a tablespace has the same number of bytes. As of Oracle9i,different tablespaces within a database can have database blocks with different sizes. Typically,one or more rows of a table will reside in a database block, although very long rows may spanseveral database blocks. Extents group together logically contiguous database blocks in a tablespace. All database blockswithin a single extent will store the same kind of information. A database block can have a size of 2KB, 4KB, 8KB, 16KB, or 32KB. Once any tablespace, including the SYSTEM tablespace, iscreated with a given block size, it cannot be changed. If you want the tablespace to have alarger or smaller block size, you need to create a new tablespace with the new block size, movethe objects from the old tablespace to the new tablespace, and then drop the old tablespace.