ADBMS Lab Program Word
ADBMS Lab Program Word
Sl.
No
PROGRAM
02.
VIVA QUESTIONS
TABLE OF CONTENT
14SCS13
Page. No
3 10
11 - 12
13 - 15
16 - 29
30 - 47
14SCS13
I.A. Marks : 20
Exam Hours: 03
COURSE OUTCOMES:
Upon completion of the course, the students will be able to
Select the appropriate high performance database like parallel and distributed database
Model and represent the real world data using object oriented database
Embed the rule set in the database to implement data warehousing of mining
Choose and design database for recent applications database for better interoperability
Programs:
1. Develop a database application to demonstrate storing and retrieving of BLOB and
CLOB objects.
2. Develop a database application to demonstrate the representation of multivalued
attributes, and the use of nested tablesto represent complex objects. Write suitable queries
to demonstrate their use.
3. Design and develop a suitable Student Database application. One of the attributes to
me maintained is the attendance ofa student in each subject for which he/she has enrolled.
Using TRIGGERS, write active rules to do the following:
a. Whenever the attendance is updated, check if the attendance is less than 85%; if so,
notify the Head of the Departmentconcerned.
b. Whenever, the marks in an Internal Assessment Test are entered, check if the marks
are less than 40%; if so, notify theHead of the Department concerned.
4. Design, develop, and execute a program in a language of your choice to implement any
one algorithm for mining association rules. Run the program against any large database
available in the public domain and discuss the results.
SJBIT DEPT. OF CSE
Page 2
14SCS13
PROGRAM 1.
Develop a database application to demonstrate storing and retrieving of BLOB
and CLOB object.
Theory:CLOB stands for Character Large Object. It is a datatype used to store and
retrieve large amount of text data in character format. CLOB datatypes are
created by using CREATE commands. It can store Single byte and multiple byte
character data. It supports both fixed width and variable width character set.
A CLOB contains a logical pointer to a CLOB, not the CLOB itself. CLOB
columns are referred as LONG VARCHAR.
BLOB stands for Binary Large object or Basic Large Object. It is a datatype
used to store unstructured binary large objects. It is an array of bytes(byte[])
stored in the database. It is not case sensitive Blobs are used to hold multimedia
objects. BLOBs fields are normally used to store graphics, audio, video, still
images and so on.
Insertb.java
Packagevemana;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.IOException;
importjava.io.PrintWriter;
importjava.sql.Connection;
importjava.sql.DriverManager;
SJBIT DEPT. OF CSE
Page 3
14SCS13
importjava.sql.PreparedStatement;
importjava.sql.SQLException;
importjava.util.logging.Level;
importjava.util.logging.Logger;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
public class insertb extends HttpServlet {
protected void doGet (HttpServletRequest request, HttpServletResponse response)
throwsServletException, IOException {
FileInputStream is = null;
response.setContentType("text/html;charset=UTF-8");
14SCS13
out.println("</html>");
}
catch(Exception e)
{
System.out.println(e);
}
finally
{ out.close(
);
}
}
}
GetBLOB.java
packagevemana;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.OutputStream;
importjava.sql.Blob;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
public class GetBLOB extends HttpServlet
{
protected void processRequest (HttpServletRequest request, HttpServletResponse
response)
throwsServletException, IOException
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connectioncon=DriverManager.getConnection("jdbc:oracle:thin:@localho
st:1521:xe", "hr", "hr");
processRequest(request, response);
}
Bdisplay.java
packagevemana;
importjava.io.IOException;
importjava.io.PrintWriter;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
public class bdisplay extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throwsServletException, IOException
{
String id;
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try
{
out.println("<html>");
out.println("<body>");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",
"hr", "hr");
PreparedStatementps = con.prepareStatement("select * from pic");
ResultSetrs = ps.executeQuery();
out.println("<h1>Photos</h1>");
while ( rs.next())
{
id=rs.getString("id");
out.println("<h4>" +id+ "</h4>");
out.println("<img width='160' height='160'
src=GetBLOB?id="+id+"></img><p/>");
}
out.println("</body>");
out.println("</html>");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}
Steps for storing and retrieving of BLOB and CLOB object:
Step 1:
Step 2:
Creating a BLOB.
Step 3:
Step 4:
Step 5:
Step 6: Storing and Retrieving of BLOB and CLOB object was displayed successfully.
OUTPUT:
CONCLUSION: - An application for storing and retrieving of BLOB and CLOB object
wasimplemented successfully.
PROGRAM 2.
Develop a database application to demonstrate the representation of multivalued
attributes, and use of nested tables to represent complex objects. Write suitable
queries to demonstrate it.
Theory:-
SQL >COMMIT;
Commit complete.
COL1
MY_TAB_V('A')
MY_TAB_V('B', 'C')
ID COLUMN_VALUE
6 rows selected.
Conclusion: - Application to demonstrate the representation of multivalued attributes,
and use of nested tables to represent complex objects was successfully executed with the
help of above queries.
PROGRAM 3.
Design and develop a suitable student database application .one of the attributes to be
maintained is the attendance of a student in each subject for which he/she has enrolled.
Using TRIGGERS, write active rules to do the following
a)
Whenever the attendance is updated, check if the attendance is less than 85%, if
so notify the head of the department concerned.
b)
Whenever the marks in an internal assessment test are entered, check if the
marks is less than 40%, if, so notify the head of the department concerned.
create table stud_rec(regno varchar(10) primary key,name varchar2(10) not null,major
varchar2(10),mark number(4),attendence number(4));
Table created. SQL>
desc stud_rec;
Name
Null?
Type
REGNO
NOT NULL
VARCHAR2(10)
NAME
NOT NULL
VARCHAR2(10)
MARKS
VARCHAR2(10)
MAJOR
NUMBER(4)
ATTENDENCE
NUMBER(4)
values('002','john','cse',30,70)
1 row created.
SQL> /
Enter value for regno: 003
Enter value for name: arun
Enter value for major: cse
Enter value for mark: 90
Enter value for atttendance: 95
old 1: insert into stud_rec values('®no','&name','&major',&mark,&atttendance)
new 1: insert into stud_rec
values('003','arun','cse',90,95)
1 row created.
SQL> select * from stud_rec;
REGNO
NAME
MARKS
MAJOR
ATTENDENCE
001
pinky
cse
85
70
002
john
cse
30
70
003
arun
cse
90
95
Trigger created.
SQL> select * from stud_rec;
REGNO
001
NAME
MARKS
pinky
cse
MAJOR
85
ATTENDENCE
70
002
john
cse
30
70
003
arun
cse
90
95
NAME
MARKS
MAJOR
ATTENDENCE
001
pinky
cse
85
25
002
john
cse
30
70
003
arun
cse
90
95
PROGRAM 4.
Design, develop and execute a program in a language of your choice to implement
any one algorithm for mining association rules. Run the program against any large
package apriori;
import java.io.*;
import java.util.*;
* Purpose
: generate Aprioriitemsets
***************************************************************/
class AprioriCalculation
{
Vector<String> candidates=new Vector<String>(); //the current candidates
String configFile="config.txt"; //configuration file
String transaFile="transa.txt"; //transaction file
String outputFile="apriori-output.txt";//output file
intnumItems; //number of items per transaction
intnumTransactions; //number of transactions
/***************************************************************
* Method Name : aprioriProcess
* Purpose
* Parameters : None
* Return : None
***************************************************************/
public void aprioriProcess()
{
Date d; //date object for timing purposes
long start, end; //start and end time
intitemsetNumber=0; //the current itemset being looked at
//get config
getConfig();
System.out.println("Apriori algorithm has started.\n");
//start timer
d = new Date();
start = d.getTime();
System.out.println(candidates);
}
//if there are <=1 frequent items, then its the end. This prevents reading through the
database again. When there is only one frequent itemset.
}while(candidates.size()>1);
//end timer
d = new Date();
end = d.getTime();
//display the execution time
System.out.println("Execution time is: "+((double)(end-start)/1000) + " seconds.");
}
/***************************************************************
* Method Name : getInput
* Purpose
* Parameters : None
* Return
***************************************************************/
public static String getInput()
{
String input=""; //read
from System.in
}
return input;
}
/***************************************************************
* Method Name : getConfig
* Purpose
filename)
*: configFile and transaFile will be change appropriately
* Parameters : None
* Return : None
***************************************************************/
private void getConfig()
{
FileWriterfw;
BufferedWriterfile_out;
String input="";
//ask if want to change the config
System.out.println("Default Configuration: ");
transaFile=input;
System.out.print("Enter new configuration filename (return for '"+configFile+"'):
");
input=getInput();
if(input.compareToIgnoreCase("")!=0)
configFile=input;
System.out.print("Enter new output filename (return for '"+outputFile+"'): ");
input=getInput();
if(input.compareToIgnoreCase("")!=0)
outputFile=input;
System.out.println("Filenames changed");
System.out.print("Enter the separating character(s) for items (return
for '"+itemSep+"'): ");
input=getInput();
if(input.compareToIgnoreCase("")!=0)
itemSep=input;
}
try
{
FileInputStreamfile_in = new FileInputStream(configFile);
BufferedReaderdata_in = new BufferedReader(new InputStreamReader(file_in));
//number of items
numItems=Integer.valueOf(data_in.readLine()).intValue();
//number of transactions
numTransactions=Integer.valueOf(data_in.readLine()).intValue();
//minsup
minSup=(Double.valueOf(data_in.readLine()).doubleValue());
System.out.println(e);
}
}
/***************************************************************
* Method Name : generateCandidates
* Purpose
*
: None
***************************************************************/
private void generateCandidates(int n)
{
Vector<String>tempCandidates = new Vector<String>(); //temporary candidate
string vector
String str1, str2; //strings that will be used for comparisons
StringTokenizer st1, st2; //string tokenizers for the two itemsets being compared
//if its the first set, candidates are just the numbers
if(n==1)
{
for(inti=1; i<=numItems; i++)
{
tempCandidates.add(Integer.toString(i));
}
}
else if(n==2) //second itemset is just all combinations of itemset 1
{
//add each itemset from the previous frequent itemsets
together for(inti=0; i<candidates.size(); i++)
{
st1 = new StringTokenizer(candidates.get(i));
str1 = st1.nextToken();
for(int j=i+1; j<candidates.size(); j++)
{
//if they have the same n-2 tokens, add them together
if(str2.compareToIgnoreCase(str1)==0)
tempCandidates.add((str1 + " " + st1.nextToken() + " " +
st2.nextToken()).trim());
}
}
}
//clear the old candidates
candidates.clear();
//set the new ones
candidates = new Vector<String>(tempCandidates);
tempCandidates.clear();
}
/***************************************************************
* Method Name : calculateFrequentItemsets
* Purpose
break;
}
if(match) //if at this point it is a match, increase the count
count[c]++;
}
}
//if error at all in this process, catch it and print the error
messate catch(IOException e)
{
System.out.println(e);
}
//clear old candidates
candidates.clear();
//new candidates are the old frequent candidates
candidates = new Vector<String>(frequentCandidates);
frequentCandidates.clear();
}
}
Input:
Output:-
14SCS13
14SCS13
Page 31
14SCS13
Page 32
14SCS13
CKPT - When a checkpoint occurs, Oracle must update the header of all data files to
highest SCN to indicate the checkpoint.
Dnnn - Dispatcher processes allow user processes to share a limited number of server
processes.
ARCH - Archiver process (ARCH) copies online redo log files to a designated storage
device once they become full. ARCH is present only when the redo log is used in
ARCHIVELOG mode and automatic archiving is enabled.
15. What is checkpoint?
Ans.When a checkpoint occurs, Oracle must update the headers of all datafiles to indicate
the checkpoint. If you are not enabled CKPT using CHECKPOINT_PROCESS, this
job is performed by LGWR, in oracle 8 CKPT by default enabled.
16. Is checkpoint optional? Then which one will take care of ckpt is not present?
Ans.Yes. Checkpoint is optional. If you are not enabled CKPT using
CHECKPOINT_PROCESS=TRUE, this job is performed by LGWR
17. Which background process you can have more than in an instance?
Ans.Dnnn. You can create multiple dispatcher processes for a single database instance.
18. When the data buffer will be flushed into respective files?
Ans.1. When ever dirty list gets filled.
2. When ever checkpoint is taking place.
19. What is parameter file?
Ans.The parameter file is a text file that contains a list of parameters and a value for each
parameter. This file will read in the NOMOUNT stage. The default parameter file
name is INITORCL.ORA (ORCL is SID).
20. Which parameter cant be changed after the init file has been set?
Ans.DB_BLOCK_SIZE. If you want change the block size you have to recreate the
database.
21. Explain the steps involved in creating new database?
Ans.a) Create the parameter file say INITTEST.ORA made the needful changes
b) Set SID say oracle_sid = TEST
c) Create a password file using ORAPWD utility.
d) Go to SVRMGR tool startup the database in NOMOUNT stage
e) Execute the script CREATE DATABASE which already prepared by DBA.
f) After created the database, run two scripts CATALOG.SQL and CATPROC.sql to
create data dictionary views and PL/sql packages.
22. What is the physical layout of the database?
Ans.One or More Data files, Two or more Log files and one or more Control files.
Page 33
14SCS13
Page 34
14SCS13
Ans.Shrink:
Using this parameter, you can manually decrease the size of a rollback
segment in Alter statement
Eg.
The following statement shrinks rollback segment RBS1 to 100K:
ALTER ROLLBACK SEGMENT rbs1 SHRINK TO 100K;
Optimal:
Using this parameter, you can decrease the size of a rollback segment
Automatically. This parameter you can specify either Create or Alter statement for
rollback segments.
Eg.
The following statement shrinks rollback segment RBS1 to 50K
automatically whenever free extents coming down less than 50k:
ALTER ROLLBACK SEGMENT rbs1 storage (OPTIMAL 100K);
30. Explain the functionality of rollback segments?
Ans.1. Rolling back Old Values
2. Providing read consistency and
3. Instance recovery
31. Why temporary segment?
Ans.When processing queries with ORDER BY, DISTINCT, GROUP BY, UNION, and
INTERSECT clause and creating index, oracle requires temporary workspace for
intermediate stages of SQL statement processing. Oracle automatically allocates this
disk space called a temporary segment.
32. When to bring the rollback segment offline?
Ans.i) When you want to take a tablespace offline and the tablespace contains
rollback segments. You cannot take a tablespace offline if it contains rollback
segments that transactions are currently using. To prevent associated rollback
segments from being used, you can take them offline before taking the tablespace
offline.
ii). You want to drop a rollback segment, but cannot because transactions are
currently using it. To prevent the rollback segment from being used, you can take it
offline before dropping it.
Syntax.
ALTER ROLLBACK SEGMENT user_rs_2 OFFLINE;
Note: You cannot take the SYSTEM rollback segment offline.
33. What is deferred rollback segment?
Ans.Deferred rollback segments are rollback segments that were created to hold
rollback entries for tablespaces taken offline until the tablespaces are brought back
online.
34. What is pending offline?
Ans.If you try to take a rollback segment offline that contains rollback data for active
SJBIT DEPT. OF CSE
Page 35
14SCS13
Page 36
14SCS13
Page 37
14SCS13
Page 38
14SCS13
CREATE SYNONYM
CREATE TABLE and
CREATE VIEW
Recourse roles privileges : CREATE CLUSTER
CREATE PROCEDURE
CREATE SEQUENCE
CREATE TABLE and CREATE TRIGGER
Dba roles privileges. : All systems privileges WITH ADMIN OPTION .
60. What are the types of privileges?
Ans.Object privileges and System privileges.
61. What is role and how to create a role
Ans.A role is a set of privileges that can be granted to users or to other roles.
Syntax.
SVRMGR> CREATE ROLE <R.NAME> IDENTIFIED BY <P.WORD>;
62. On what privileges, with admin option cant be given.
Ans.Object privileges. Because with admin option only for system privileges.
63. What is cascading effect?
Ans.If you revoke an object privilege from a user who has granted the privilege to
other users or roles, Oracle7 also revokes the privilege from the grantees.
64. What is auditing?
Ans.Auditing keeps track of operations performed by database users. Audit record
containing this information like user performing the operation, type of operation,
object involved in the operation, date and time of the operation.
65. What is object audit, how to enable it and where will you see the result?
Ans.To audit all successful and unsuccessful DELETE statements on the EMP table,
BY SESSION (the default value), enter the following statement:
AUDIT DELETE ON emp;
SELECT * FROM sys.dba_obj_audit_opts;
66. What is statement audit, how to enable it and where will you see the result?
Ans.To audit all successful and unsuccessful connections to and disconnection
from the database BY SESSION (the default and only value for this option), enter the
following statement:
AUDIT SESSION BY Scott, lori;
SELECT * FROM sys.dba_stmt_audit_opts;
67. What is privilege audit, how to enable it and where will you see the result?
Ans.To audit all unsuccessful SELECT, INSERT, and DELETE statements on all
tables and unsuccessful uses of the EXECUTE ANY PROCEDURE system privilege,
by all database users, BY ACCESS, enter the following statement:
SJBIT DEPT. OF CSE
Page 39
14SCS13
Page 40
14SCS13
Page 41
14SCS13
Page 42
14SCS13
Page 43
14SCS13
Page 44
14SCS13
Page 45
14SCS13
Page 46
14SCS13
Page 47
14SCS13
126.What is Savepoint?
Ans.To identify a point in a transaction to which you can later roll back.
127.What is truncate command?
Ans.To remove all rows from a table or cluster and reset the STORAGE parameters to
the values when the table or cluster was created.
128.What is PL/sql?
Ans.PL/SQL (Procedural Language/SQL) is set of procedural capabilities that extend
the power of traditional SQL. PL/sql statements can be combined with traditional SQL in
variety of SQL products to increase the ease of application programming, and
considerably overall system performance.
Block Structure:
Declare
<Local declaration>
Begin
<Statements>
Exception
<Error handler>
End;
129.What is ODBC?
Ans.Open Database Connectivity.
A standard protocol for accessing Relational Database around sql.
130.What is referential integrity constraint?
Ans.A referential integrity constraint designates a column or combination of columns
as a foreign key and establishes a relationship between that foreign key and a specified
primary or unique key, called the referenced key. In this relationship, the table containing
the foreign key is called the child table and the table containing the referenced key is
called the parent table.
131.What is stand by database?
Ans.A standby database maintains a duplicate, or standby copy of your primary
database and provides continued primary database availability in the event of a disaster
(when all media is destroyed at your production site).
A standby database is constantly in recovery mode. If a disaster occurs, you can
take the standby database out of recovery mode and activate it for online use. Once you
activate your standby database, you cannot return it to standby recovery mode unless you
re-create it as another standby database.
Page 48