Professional Documents
Culture Documents
Laboratory Record Note Book: Rajalakshmi Institute of Technology
Laboratory Record Note Book: Rajalakshmi Institute of Technology
NAME : DEEPAK M
SEMESTER :IV
1
211719104031
RAJALAKSHMI INSTITUTE OF
TECHNOLOGY
KUTHAMBAKKAM, CHENNAI-600124.
BONAFIDE CERTIFICATE
NAME : DEEPAK M
SEMESTER :IV
BRANCH :CSE
Certified that this is a bonafide record of work done by the above student in
the
InternalExaminer ExternalExamine
2
211719104031
INDEX
Name: DEEPAK M Sec: A
3a 04-03-2021 Views 18
3b 11-03-2021 Sequences 21
3c 18-03-2021 Synonyms 23
DATABASE PROGRAMMING
5a 15-04-2021 Procedures 28
5b 22-04-2021 Functions 32
6 29-04-2021 Triggers 36
3
211719104031
DATE : 18-02-2021
AIM:
To create table and implement data definition and data manipulation commands in SQL
DESCRIPTION:
Creating a table
Altering table structure by adding, deleting or modifying columns
Destroy databases and database objects.
These commands will primarily be used by database administrators during the setup and removal
phases of a database project.
THE ORACLE TABLE – DUAL - Dual is a small oracle table which consists of only
onerow and one column and contains the value X in that column.
SELECT - This command is used to display the contents of the table or those of
aparticular column.
UPDATE-A SQL UPDATE statement that changes the data of one or more records in
atable. Either all the rows can be updated, or a subset may be chosen using a condition
DELETE -An SQL DELETE statement removes one or more records from a table.
Asubset may be defined for deletion using a condition, otherwise all records are removed
4
211719104031
COMMIT - This command is used to permanently stored the data in the database.
SQL> create table stud (snamevarchar2(30), sid varchar2(10), sage number(2), sarea
varchar2(20));
Table created.
SQL>desc stud;
NameNull? Type
------------------------- -------- --------------------------------
SNAMENullVARCHAR2(30)
SIDNullVARCHAR2(10)
SAGENullNUMBER(2)
SAREANullVARCHAR2(20)
ALTER TABLE
Table altered.
SQL>desc stud;
NameNull? Type
---------------------------------- -------- --------------------------------
SNAME Null VARCHAR2(30)
SIDNull VARCHAR2(10)
SAGE Null NUMBER(10)
SAREANull VARCHAR2(20)
5
211719104031
Table altered.
SQL>desc stud;
NameNull? Type
----------------------- -------- --------------------------------
SNAME null VARCHAR2(30)
SID VARCHAR2(10)
SAGE NUMBER(10)
SAREA VARCHAR2(20)
SDEPT VARCHAR2(20)
Table altered.
SQL>desc studs;
NameNull? Type
------------------------------ -------- --------------------------------
SNAME VARCHAR2(30)
SID VARCHAR2(10)
SAGE NUMBER(10)
SAREA VARCHAR2(20)
TRUNCATE TABLE:
TRUNCATE TABLE removes all rows from a table, but the table structure and its columns,
constraints, indexes and so on remain.
SQL> truncate table studs;
Table truncated.
SQL>desc studs
NameNull? Type
----------------------------- -------- ------------------------------------
SNAME VARCHAR2(30)
SID VARCHAR2(10)
SAGE NUMBER(10)
SAREA VARCHAR2(20)
SDEPT VARCHAR2(20)
6
211719104031
DROP TABLE:
Drop table removes one or more table definitions completely from the database,by removing
all data, indexes, triggers, constraints, and permission specifications for those tables.
SQL> drop table studs;
Table dropped.
CREATION OF TABLE
SYNTAX:
1 row created.
1 row created.
7
211719104031
m
Pruthvik 103 20 Annanagar Aerospace
Charith 104 20 Kilpauk Mechanical
UPDATING THE TABLE:
SYNTAX:
UPDATEtable_name SETcolumn_name = value [, column_name = value ...]
[WHEREcondition]
TCL COMMANDS
COMMIT:
SQL> commit;
The data is stored permanently.
SAVE POINT:
8
211719104031
SQL>savepoint A;
9
211719104031
RESULT :
Thus the SQL commands for data definitions and data manipulation have been executed and the
output have been verified.
10
211719104031
DATE :25-02-2021
AIM:
To create table and execute simple and nested queries using SQL commands
DESCRIPTION:
ORDER BY CLAUSE - The order by clause arranges the contents of the table inascending
order (by default) or in descending order (if specified explicitly) according to the specified
column.
GROUP BY CLAUSE-The group by clause is another section of the select statement. This
optional class tells oracle to group rows based on distinct values that exists for specified
columns.
The having clause can be used in conjunction with the group by clause. Having imposes a
condition on the group by clause, which further filters the groups created by the group by
clause.
UNION CLAUSE: Multiple queries can be put together and their output combined using the
union clause. The union clause merges the output of two or more queries into a single set of
rows and columns.
INTERSECT CLAUSE: Multiple queries can be put together and their output can be
combined using the intersect clause. The intersect clause outputs only rows produced by both
the queries intersected. The output in an intersect clausewill include only those rows that are
retrieved by both the queries. SQL Correlated Subqueries
Correlated subqueries are used for row-by-row processing. Each subquery is executed once for
every row of the outer query.
JOINS:
Joins are normally used to retrieve data from more than one table
The keyword JOIN, joins one or more tables together in a results set.
To perform a join, there must be a common key that defines how the rows in the table
correspond to each other.
All sub-queries can be converted to joins, however ,all joins cannot be converted to sub-queries.
11
211719104031
COMMANDS
Subquery Syntax
SELECT select_list FROM table WHERE expr operator (SELECT select_list FROM
table);
– The subquery (inner query) executes once before the main query (outer query).
– In the syntax:
– WHERE clause
– HAVING clause
– FROM clause
BETWEEN OPERATOR
SQL> select sname,sarea, sid from studs where sid between 102 and 104;
12
211719104031
GROUP BY CLAUSE:
SAREA RESULT
-------------------- ------------
Annanagar1000
nungambakkam500
kilpauk100
HAVING CLAUSE:
SQL> select sarea, sum(spocket) result from studs group by sarea having spocket<600;
SAREA RESULT
-------------------- ------------
nungambakkam 500
kilpauk100
Table created.
1 row created.
1 row created.
1 row created.
SQL> insert into product values('sofa',10010);
1 row created.
13
211719104031
1 row created.
1 row created.
SQL> select * from sale;
PRODNAME ORDERNO PRODNO
-------------
---------------------------- - ----------
14
211719104031
SET OPERATIONS:
SQL> select prodname from product where prodno=10010 union select prodname from sale where
prodno=10010;
PRODNAME
------------------
chair
sofa
SQL> select prodname from product where prodno=11110 intersect select prodname from sale
where prodno=11110;
PRODNAME
-----------------------------
Cot
CORRELATED SUBQUERY
A correlated subquery is evaluated once for each row processed by the parent statement.
The parent statement can be a SELECT, UPDATE, or DELETE statement.
A correlated subquery is one way of reading every row in a table and comparing values in
each row against related data. It is used whenever a subquery must return a different result
or set of results for each candidate row considered by the main query. In other words, user
can use a correlated subquery to answer a multipart question whose answer depends on the
value in each row processed by the parent statement.
CORRELATED UPDATE :
15
211719104031
SQL> UPDATE table1 alias1SET column = (SELECT expression From table2 alias2WHERE
alias1.column =alias2.column);
Use a correlated subquery to update rows in one table based on rows from another table.
16
211719104031
JOINS:
CARTESIAN JOIN:
A Cartesian join is also known as cross join.
If there are two tables, then the Cartesian join is obtained when every row of one table is
joined to a row in another table.
SYNTAX
EXAMPLE:
SQL>SELECT * FROM EMP,DEPT;
INNER JOIN:
The inner join joins two or more tables, returning only matched rows;
It require that both tables involved in join must have a primary- foreignkey relationship.
Example for an employee and department table ‘a’ is the alias for employee
‘b’ is the alias for department
Here ‘a’ is the alias name for Here ‘b’ is the alias name for
emp_id,enam
location
17
211719104031
OUTER JOIN:
The SQL OUTER JOIN command is used to display the elements in a table,regardless of
whether they are present in the second table.
ISO method->(+) by placing this symbol in where clause,on the other side of the table,for
which all the rows need to be included.(available in Oracle 8i).
SYNTAX:
SELECT Column_list FROM Left_table LEFT [OUTER] JOIN Right_Table ON Condition.
SYNTAX:
18
211719104031
SYNTAX:
A full outer join is essentially a combination of left and right outer joins, i.e.
The records from the table on left are included even if there are no matching records on the
right.
The records from the table on the right are included even if there are no matching record on the left.
SYNTAX:
SELECT Column_list FROM left_table FULL [OUTER] JOIN right _table ON condition.
RESULT:
Thus, the SQL commands for database querying using simple and nested queries have been
executed successfully and the output is verified.
19
211719104031
EX.NO:3a) VIEWS
DATE: 04-03-2021
AIM:
1.Query to create a view to have customer name and age from the CUSTOMERS table.
View created.
20
211719104031
Updating a View
set age = 35
where name = 'Ramesh';
Output:
OUTPUT:
Dropping Views
1.Query to drop the CUSTOMERS_VIEW from the CUSTOMERS table.
21
211719104031
View dropped.
OUTPUT:
RESULT:
Thus the SQL commands to execute views have been executed successfully and the output is
verified.
22
211719104031
EX.NO:3b) SEQUENCES
DATE: 11-03-2021
AIM:
SYNTAX:
SQL>
create sequence sequence_1
start with 1
increment by 1
minvalue 0
maxvalue 100
cycle;
Sequence created.
Table created.
1 row(s) inserted.
1 row(s) inserted.
OUPUT:
I
NAME
D
Rames
1
h
2 Suresh
23
211719104031
Dropping Sequences
Sequence dropped.
SQL>
create sequence sequence_2
start with 100
increment by -1
minvalue 1
maxvalue 100
cycle;
Sequence created.
Table created.
1 row(s) inserted.
1 row(s) inserted.
OUTPUT:
ID NAME
100 Ramesh
99 Suresh
DROPPING SEQUENCES:
Sequence dropped.
RESULT:
24
211719104031
Thus the SQL commands to execute sequences have been executed successfully and the output
is verified
EX.NO:3c) SYNONYMS
DATE: 18-03-2021
AIM:
Table created.
1 row(s) inserted.
1 row(s) inserted.
SQL>select * from s;
I
NAME
D
Rames
1
h
2 Suresh
RESULT:
25
211719104031
Thus the SQL commands to execute synonyms have been executed successfully and the output
is verified
EX.NO:4 DATABASE PROGRAMMING
EX.NO:4a)IMPLICIT CURSOR
DATE:25-03-2021
AIM:
To implement data programming using implicit cursors using SQL commands.
SQL> create table customers(id number, name varchar2(10), age number, address
varchar2(30),salary number);
Table created.
SQL>
Declare
total_rows number(2);
begin
update customers
ifsql%notfound then
elsifsql%found then
26
211719104031
total_rows := sql%rowcount;
end if;
end;
OUTPUT:
6 customers selected
1 row(s) updated.
RESULT:
Thus the SQL program to execute data programming using implicit cursors have been executed
successfully and the output is verified.
27
211719104031
EX.NO:4b)EXPLICIT CURSORS
DATE: 08-04-2021
AIM: To implement data programming using explicit cursors using SQL commands.
SYNTAX:
Table created.
SQL>
declare
c_idcustomers.id%type;
c_namecustomers.name%type;
c_addrcustomers.address%type;
cursorc_customers is
begin
openc_customers;
loop
end loop;
closec_customers;
end;
OUTPUT:
1 Ramesh Ahmedabad
2 Khilan Delhi
3 kaushik Kota
4 Chaitali Mumbai
5 Hardik Bhopal
6 Komal MP
RESULT:
Thus, the SQL program to execute data programming using explicit cursors have been executed
successfully and the output is verified.
29
211719104031
EX.NO:5a)PROCEDURES
DATE:15-04-2021
AIM:
To implement procedures using SQL programming.
SYNTAX:
(i) Write a PL/SQL Procedure that displays the string 'Hello World!'
SQL>
create or replace procedure greetings
as
begin
dbms_output.put_line('Hello World!');
end;
/
begin
greetings;
end;
/
OUTPUT:
Hello World
Statement processed.
(ii) Write a PL/SQL Procedure that finds the minimum of two values.
SQL>
declare
a number;
b number;
30
211719104031
c number;
begin
if x < y then
z:= x;
else
z:= y;
end if;
end;
begin
a:= 23;
b:= 45;
findmin(a, b, c);
end;
Output:
(iii) Write a PL/SQL Procedure that computes the square of value of a passed value.
SQL>
Declare
a number;
begin
31
211719104031
x := x * x;
end;
begin
a:= 23;
squarenum(a);
end;
Output:
Table created
SQL>
create or replace procedure "insertuser" (id in number, name in varchar2)
is
begin
insert into user1 values(id,name);
end;
/
Procedure created.
SQL>
begin
insertuser(101,'Rahul');
dbms_output.put_line('Record inserted successfully');
end;
/
Record inserted successfully
Statement processed.
OUTPUT:
32
211719104031
Nam
ID
e
10
Rahul
1
33
211719104031
RESULT:
Thus,the SQL programs to execute procedures have been executed and the output is verified.
34
211719104031
EX.NO:5b)FUNCTIONS
DATE:22-04-2021
AIM:
SYNTAX:
(i) Write a PL/SQL function that computes and returns the addition of two numbers.
SQL>
create or replace function adder(n1 in number, n2 in number)
return number
is
n3 number(8);
begin
n3 :=n1+n2;
return n3;
end;
/
Function created
declare
n3 number(2);
begin
n3 := adder(11,22);
dbms_output.put_line('Addition is: ' || n3);
end;
/
OUTPUT:
Addition is: 33
Statement processed.
(ii) Write a PL/SQL function that computes and returns the maximum of two values.
SQL>
35
211719104031
declare
a number;
b number;
c number;
function findmax(x in number, y in number)
return number
is
z number;
begin
if x > y then
z:= x;
else
z:= y;
end if;
return z;
end;
begin
a:= 23;
b:= 45;
c := findmax(a, b);
dbms_output.put_line(' Maximum of (23,45): ' || c);
end;
/
OUTPUT:
Maximum of (23,45): 45
Statement processed.
(iii) Write a PL/SQL function that will return the total number of CUSTOMERS in the
customers table.
SQL> create table customers(id number, name varchar2(10), age number, address varchar2(30),
salary number);
Table created.
36
211719104031
SQL>
create or replace function totalcustomers
return number is
total number(2) := 0;
begin
select count(*) into total from customers;
return total;
end;
/
Function created.
declare
c number(2);
begin
c := totalcustomers();
dbms_output.put_line('Total no. of Customers: ' || c);
end;
/
OUTPUT:
SQL>
declare
num number;
factorial number;
function fact(x number)
return number
is
37
211719104031
f number;
begin
if x=0 then
f := 1;
else
f := x * fact(x-1);
end if;
return f;
end;
begin
num:= 6;
factorial := fact(num);
dbms_output.put_line(' Factorial '|| num || ' is ' || factorial);
end;
/
OUTPUT:
Factorial 6 is 720
Statement processed.
RESULT:
38
211719104031
Thus,the SQL programs to execute functions have been executed and the output is verified.
39
211719104031
EX.NO:6TRIGGERS
DATE: 29-04-2021
AIM:
Table created.
40
211719104031
SQL>
Trigger created.
SQL>update customers
41
211719104031
OUTPUT:
RESULT:
42
211719104031
Thus,the SQL programs to execute triggers have been executed successfully and the output is
verified.
43
211719104031
DATE :06-05-2021
AIM:
THEORY:
User-defined exceptions
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling goes here >
........
44
211719104031
exception3-handling-statements
END;
Example
DECLARE
pssn number(4);
pfname varchar2(15);
pbdate date;
BEGIN
SELECT fname, bdate INTO pfname, pbdate
FROM employee205
WHERE ssn = &pssn;
DBMS_OUTPUT.PUT_LINE ('Name: '|| pfname);
DBMS_OUTPUT.PUT_LINE ('Date of Birth: ' || pbdate);
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line('No such Employee!');
WHEN others THEN
dbms_output.put_line('Error!');
END;
EXECUTION 1:
Enter value for pssn: 999
old 8: WHERE ssn = &pssn;
new 8: WHERE ssn = 999;
Name: NANDA
Date of Birth: 30-MAY-05
45
211719104031
EXECUTION 2:
Raising Exceptions
Exceptions are raised by the database server automatically whenever there is any internal
database
error, but exceptions can be raised explicitly by the programmer by using the command
RAISE.
DECLARE
exception_name EXCEPTION;
BEGIN
IF condition THEN
RAISE exception_name;
END IF;
EXCEPTION
WHEN exception_name THEN
statement;
END;
USER-DEFINED EXCEPTIONS:
46
211719104031
PL/SQL allows to define own exceptions according to the need of the program. A user-
defined exception must be declared and then raised explicitly, using either a RAISE
statement or the procedure
DBMS_STANDARD.RAISE_APPLICATION_ERROR.
DECLARE
my-exception EXCEPTION;
Example:
The following example illustrates the concept. This program asks for assn, when the user
enters an invalid ssn, the exception invalid_ssn is raised.
DECLARE
pssn number(4);
inputssn number(4);
pfname varchar2(15);
pbdate date;
invalid_ssn EXCEPTION;
BEGIN
PSSN:=&inputssn;
IF Pssn<= 0 THEN
RAISE invalid_ssn;
ELSE
SELECT fname, bdate INTO pfname, pbdate
FROM employee205
WHERE ssn = pssn;
DBMS_OUTPUT.PUT_LINE ('Name: '|| pfname);
DBMS_OUTPUT.PUT_LINE ('Date of Birth: ' || pbdate);
END IF;
EXCEPTION
WHEN invalid_ssn THEN
dbms_output.put_line('SSN must be greater than zero!');
WHEN no_data_found THEN
47
211719104031
SQL> /
Enter value for inputssn: 200
old 8: PSSN:=&inputssn;
new 8: PSSN:=200;
No such Employee!
SQL> /
Enter value for inputssn: 0
old 8: PSSN:=&inputssn;
new 8: PSSN:=0;
SSN must be greater than zero!
PL/SQL procedure successfully completed.
48
211719104031
RESULT:
Thus,the SQL programs to execute triggers have been executed successfully and the output is
verified.
49
211719104031
APPLICATION
DATE: 10-05-2021
AIM:
ER DIAGRAM:
CHEN NOTATION:
CHEN NOTATION:
50
211719104031
REPRESENTING RELATIONSHIPS:
1: N Relationships.
Solution: Introduce a third Intersection relation and copy keys from original two
relations.
CHEN NOTATION:
51
211719104031
Note that this can also be shown in the ER diagram. Also, look for potential added
attributes in the intersection relation.
The repeating fields will be removed from the original data table, leaving the following.
52
211719104031
ItemNo, Description
All of these fields except the primary key will be removed from the original table. The primary key
will be left in the original table to allow linking of data:
Never treat price as dependent on item. Price may be different for different sales orders (discounts,
special customers, etc.)
Along with the unchanged table below, these tables make up a database in second normal form:
ClerkNo, ClerkName
All of these fields except the primary key will be removed from the original table. The primary key
will be left in the original table to allow linking of data as follows:
Together with the unchanged tables below, these tables make up the database in third normal form.
ItemNo, Description
53
211719104031
54
211719104031
RESULT:
Thus,the SQL programs to execute data design using ER modeling normalization and application
have been executed successfully and the output is verified.
55
211719104031
AIM:
Provides Access with the information it requires to join the information in the tables
together as needed.
Determine the purpose of database: This helps to prepare for the remaining steps.
2.1.2 Find and organize the information required: Gather all of the types of information to
record in the database, such as product name and order number.
2.1.3 Divide the information into tables: Divide information items into major entities
orsubjects, such as Products or Orders. Each subject then becomes a table.
56
211719104031
2.1.4 Turn information items into columns: Decide what information to store in eachtable. Each
item becomes a field, and is displayed as a column in the table. For example, an Employees
table might include fields such as Last Name and Hire Date.
2.1.5 Specify primary keys: Choose each table’s primary key. The primary key is a column thatis
used to uniquely identify each row. An example might be Product ID or Order ID.
2.1.6 Set up the table relationships: Look at each table and decide how the data in one table
isrelated to the data in other tables. Add fields to tables or create new tables to clarify the
relationships, as necessary.
2.1.7 Refine the design: Analyze the design for errors. Create the tables and add a few recordsof
sample data. See if it can get the results from the tables. Make adjustments to the design, as
needed.
These are ten general principles for user interface design. They are called "heuristics"
because they are more in the nature of rules of thumb than specific usability guidelines.by
Jakob Nielsen
The system should always keep users informed about what is going on, through
appropriate feedback within reasonable time.
The system should speak the users' language, with words, phrases and concepts familiar to
the user, rather than system-oriented terms. Follow real-world conventions, making
information appear in a natural and logical order.
57
211719104031
Users often choose system functions by mistake and will need a clearly marked "emergency
exit" to leave the unwanted state without having to go through an extended dialogue.
Support undo and redo.
Users should not have to wonder whether different words, situations, or actions mean the
same thing. Follow platform conventions.
Even better than good error messages is a careful design which prevents a problem from
occurring in the first place. Either eliminate error-prone conditions or check for them and
present users with a confirmation option before they commit to the action.
Minimize the user's memory load by making objects, actions, and options visible. The user
should not have to remember information from one part of the dialogue to another.
Instructions for use of the system should be visible or easily retrievable whenever
appropriate.
Accelerators -- unseen by the novice user -- may often speed up the interaction for the
expert user such that the system can cater to both inexperienced and experienced users.
Allow users to tailor frequent actions.
Dialogues should not contain information which is irrelevant or rarely needed. Every extra
unit of information in a dialogue competes with the relevant units of information and
diminishes their relative visibility.
Error messages should be expressed in plain language (no codes), precisely indicate the
problem, and constructively suggest a solution.
58
211719104031
Even though it is better if the system can be used without documentation, it may be
necessary to provide help and documentation. Any such information should be easy to
search, focused on the user's task, list concrete steps to be carried out, and not be too large.
It also provides capability to produce custom libraries and objects that can be loaded at
runtime or bound into the distributed application.
Every time the user load a VB or VBA project, user will be greeted by roughly the layout
shown in Figure and these five GUI tools. First, the toolbox(1) contains all the GUI
59
211719104031
elements/controls needed to create any VB form and the front end to all VB programs. For
example, after the pointer tool there is the image control, label, textbox, and frame and command
button as the first five of 20 standard controls which are used constantly in VB programs. Another
advantage of these basic controls is that they fill 60-90% of all programming needs and are
automatically included in the VB runtime.
Second is form(2). Think of it as it can size it, color it, give it a caption("Database Test" in
this case) and fill the form with GUI controls which helps the program do useful works. Putting
controls on the form is as easy as clicking on the control (say the command button) in the toolbox
and then dragging and sizing it on the form (see the "Exit" button on the form).
The third part of the Basic canvas is the menus and toolbars (3) which manage and control
all of VB/VBA.Most of us will be familiar with many of the menu and icons. File, Edit, View, Run,
Window, Help menus should be familiar to any Word Perfect, Excel, or Netscape users. Likewise
icons for File Open, File Save, Cut, Copy, Paste, Find, Run programs, Pause Program, Halt
Program can be seen along the toolbar. Along with built in wizards and custom command centers in
some controls, this is the heart of VB.
Fourth is the Project Explorer (4) which user uses to access all the forms and coding
filesin the VB program. The PE-Project Explorer is such a handy navigation device which will find
using it all the time to switch among different forms and code.
Fifth and even more frequently used than the Project Explorer is the Properties sheet (5).
Note that the "Exit" command button is highlighted in the form and is also the control listed in the
Properties sheet. The Properties sheet is both the elegance and the swamp of VB. If user want to
change the property of any control like its color, shape, caption, or whatever - the Property sheet is
the place to go. But a command button has 32 properties - and some controls have hundreds, hence
the swamp.
User will find in developing in Visual Basic that spends a large percentage of time using the
Project Explorer and Property sheet. It is worthwhile to get to know them well. Project Explorer
60
211719104031
is the means of navigating around the various parts of VB; while Property sheets allows to set the
very basic look and feel plus behavior of all the forms in Visual Basic.
The toolbox icon - toggles the main toolbox of form controls on and off.
The form icon in the Project Explorer. Click on this and the active Form
will appear in the edit window.
The Project Explorer icon - toggle this to make the Project Explorer appear
or disappear.
Property sheet icon - toggle this to make the Property sheet appear or
disappear.
FORM DESIGN:
Forms don’t usually get much attention from code-level developers. We add a form and off we
go, plugging in various controls and using them as containers for information. But setting up
forms’ properties is important for creating visually pleasant, consistent, and intuitive interfaces.
It should specify the proper border style of a form. The options are:
None
Fixed Single
Sizable
61
211719104031
Fixed Dialog
Fixed ToolWindow
Sizable ToolWindow
Using None is rarely a good idea, since such forms don’t have a title bar or the control menu
box,so users can’t close or resize them. The default form value is Sizable (allowing users to
resize theform), but this is a good choice only in cases where all the form elements are designed
to resizealong with the form itself.The Fixed Dialog style offers a border and doesn’t allow a
form to beresized, but it lacks Minimize and Maximize buttons in the top-right corner. To
include thosebuttons, use the Fixed Single style. Sizable ToolWindow and Fixed
ToolWindow styles aregenerally used for forms that need to float over and allow changes to be
made to the main forms.
User should also address the form’s start position. The available start position styles are:
Manual
Windows Default
CenterScreen
CenterOwner
The default style is Manual, which means that the form will appear in the same location at both
runtime and design time. Windows Default puts a form in the upper-left corner on the screen.
CenterScreen places a form in the center of the user’s screen regardless of the screen resolution.
CenterOwner places a form in the center of the owner form. An owner is a form on top of which
the current form is to appear. When no owner is specified, the form shows up in the center of
the desktop.
62
211719104031
Before simply dropping controls on a form, consider what kind of data the control will oversee
and how the users will interact with that data. The guidelines provided below will help user
choose the best controls for a particular type of data.
The first rule of form controls is that they should have consistent characteristics, such as look,
feel, and size. Users shouldn't need to learn specific visual cues and usage parameters for each
control.
The text box controls should be the same height as the combo boxes. By default, the height
property of text boxes is different from that of the combo boxes. User should change the height
value of the text boxes to match that of the combo boxes (since the height property is read-only
in combo boxes). Obviously, this rule applies only to single-line text boxes.
User should use the proper controls for the data need to display. If user is displaying read-only
data, you should not use a text box and modify its properties so that other users can’t make
changes to its text. Instead, use a label. Text box controls should be used only for editable data.
63
211719104031
When there is a need to display fewer than five options in a list and the user has to choose only
one item, option buttons are the best choice. Many applications use combo boxes to display
such information, but from the user's standpoint, it’s much better to see all options at once
rather than having to scroll through the listings in a combo box.
Keep in mind that when users should be able to select more than one item from a small list of
selections, using check boxes is a good idea. As with option buttons, check boxes let users see
all options available at the same time, but check boxes also allow the selection of multiple items
from the list.
When need to display a larger number of items for users to choose from, it’s not feasible to use
option buttons or check boxes because of the amount of real estate they would take up on the
form. In such cases, display data either in combo boxes or list boxes to save space.use multiple-
selection list boxes to let users select more than one item at a time; combo boxes allow only one
item to be selected.
Developers sometimes use combo boxes and list boxes to display more than one column of
data; however, grid controls may be easier for users to understand (and easier to code).
When using labels next to corresponding controls, left-align the labels and follow label captions
with a colon for better readability. Also, align labels vertically to the corresponding controls.
Figure A provides an example of these label rules in action.
FIGURE A
64
211719104031
Always set the BackStyle property of label controls to Transparent to make sure that labels have
the same BackColor as the parent form.
Whenever there is a need to prevent users from using a control temporarily, it’s preferable to
disable the control rather than hide it. Disabling a control prevents the user from clicking it, but
it doesn’t significantly alter the way the form looks. Hiding controls may take the users by
surprise or lead them to believe that something is wrong with an application. When selecting
controls, also consider newer VB options, such as Tab Control, Tree View, Progress Bar, and
Toolbar, to improve the form layout and design.
65
211719104031
MENU DESIGN:
THEORY:
To start adding menu items to the application, open an existing project or start a new
project, then click on Tools in the menu bar of the Visual Basic IDE and select Menu
Editor. click on the Menu Editor, the Menu Editor dialog will appear. In the Menu Editor
dialog , key in the first item File in the caption text box. use the ampersand ( & ) sign in
66
211719104031
front of F so that F will be underlined when it appears in the menu, and F will become the
hot key to initiate the action under this item by pressing the Alt key and the letter F. After
typing &File in the Caption text box, move to the name textbox to enter the name for this
menu item, type in menuFile here. Now, click the Next button and the menu item &File will
move into the empty space below, as shown in the following diagram:
Then add in other menu items on the menu bar by following the same procedure, as shown
in the diagram below:
67
211719104031
Click Ok, the menu items will be shown on the menu bar of the form.
Now, proceed to add the sub menus. In the Menu Editor, click on the Insert button between
File and Exit and then click the right arrow key, and the dotted line will appear. This shows
the second level of the menu, or the submenu. Now key in the caption and the name. Repeat
the same procedure to add other submenu items. Here, we are adding New, Open, Save,
Save As and Exit.
68
211719104031
Now click the OK button and go back to the form. To see the dropped down
submenus click on the item File, as shown.
PRACTICE EXERCISE:
Personal
Detail
Branch wise
Detail
Mark
Mark Detail
Grade Detail
Exit
69
211719104031
70
211719104031
71
211719104031
72
211719104031
In the Personal Information form add Menu to navigate to the Main Menu(Intro Form)
In the Mark form add Menu to navigate to the Grade Details(Grade Form)
In the Grade form add Menu to navigate to the Mark Details(Mark Form)
CODING:
73
211719104031
End Sub
Private Sub PersonalDetail_Click(Index As Integer)
Unload Me
Load Student
Student.Show
End Sub
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
End If
End Sub
Private Sub cmdmoveprev_Click()
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
End If
End Sub
74
211719104031
"'"MsgBoxcs
End Sub
Unload Me
Load Intro
Intro.Show
End Sub
75
211719104031
RESULT:
Thus,the data connectivity with front end tools has been executed successfully and the output
is verified.
DATE:23-04-2021
AIM:
To implement case study using real life database application using SQL commands.
1.Create the DB for banking system source request the using SQL
3.Click add button and select oracle in ORA home 90 click finished
4.A window will appear give the data source name as oracle and give the user id as scott
5.Now click the test connection a window will appear with server and user name give user
as scott and password tiger Click ok
76
211719104031
>>To add ADODC project select component and check ms ADO data control click
ok.
>>Now the control is added in the tool book
>>Create standard exe project in to and design ms from in request format
ADODC CONTROL FOR ACCOUNT FROM:- Click customs and property window and
window will appear and select ODBC data source name as oracle and click apply as the
some window.
Form2.Show
End Sub
77
211719104031
Private Sub
EXIT_Click()
Unload Me
End Sub
Private Sub
TRANSACTION_Click()
Form3.Show
End Sub
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub
DELETE_Click()
78
211719104031
Adodc1.Recordset.MovePrevious
End If
End Sub
Unload Me
End Sub
Private Sub
HOME_Click()
Form1.Show
End Sub
Private Sub
INSERT_Click() Adodc1.Recordset.AddNew
End Sub
Private Sub
TRANSACTION_Click()
79
211719104031
Form3.Show
End Sub
successfully"
End Sub
Form2.Show
End Sub
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub
DEPOSIT_Click()
80
211719104031
EndSub
PrivateSub
EXIT_Click()
UnloadMe
EndSub
PrivateSub
HOME_Click()
Form1.Show End
WITHDRAW_Click()
Str(A)
Adodc1.Recordset.Save
81
211719104031
Adodc1.Recordset.UPDATE
End Sub
82
RESULT:
83
Thus,the case study using real life database application has been executed successfully and
the output is verified.
84
EX.NO: 11 DISTRIBUTED DATABASE
DATE:30-04-2021
AIM:
Description:
A distributed database is a database in which storage devices are not all attached to a
common processing unit such as the CPU, controlled by a distributed database management
system. (together sometimes called a distributed database system). It may be stored in multiple
computers, located in the same physical location; or may be dispersed over a network of
interconnected computers. Unlike parallel systems, in which the processors are tightly coupled
and constitute a single database system, a distributed database system consists of loosely-coupled
sites that share no physical components.
There are two principal approaches to store a relation r in a distributed database system:
A) Replication
B) Fragmentation/Partitioning
A) Replication: In replication, the system maintains several identical replicas of the same relation
r in differentsites.
B) Fragmentation: The relation r is fragmented into several relations r1, r2, r3....rnin such a way
that the actual relation could be reconstructed from the fragments and then the fragments are
scattered to different locations. There are basically two schemes offragmentation:
Linked servers provide SQL Server the ability to access data from remote data sources. Using these
mechanisms, we can issue queries, perform data modifications and execute remote procedures.
We can use the T-SQL function OPENROWSET to query a remote data source without a linked
server.
85
Steps:
1. Create HorizontalPartition:
First partition a table horizontally. In designing a partitioning scheme, it must
be clear what data belongs to each member table. The original table is
replaced with several smaller member tables. Each member table has the
same number of columns as the original table, and each column has the same
attributes as the corresponding column in the original table, such as data type,
size, and collation. By using a distributed partitioned view, each member
table is on a separate member server. For the greatest location transparency,
the name of the member databases should be the same on each member
server, although this is not required.For
example: Server1.CustomerDB, Server2.CustomerDB, Server3.CustomerDB.
1.1 Creating Member Tables
Design the member tables so that each table stores a horizontal slice of the
original table based on a range of key values. The ranges are based on the
data values in a partitioning column. The range of values in each member
table is enforced by a CHECK constraint on the partitioning column, and
ranges cannot overlap.The CHECK constraint for this table is thefollowing:
-- On Server1:
CREATE TABLE
Customers_33
(CustomerID
INTEGER
PRIMARY KEY
CHECK (CustomerID BETWEEN 1 AND 32999),
... -- Additional column definitions)
2. Create LinkedServer:
The servers that can be referenced in queries are called linked servers. A
linked server is any data source that can be accessed using OLE DB
–It can be another SQL Serveror
–A different database server (such as Oracle)or
–A simpler data source, such as a file (Excel,Access)
Create a linked server to another SQL Server instance using the T-SQL
procedure sp_addlinkedserver. The syntax of sp_addlinkedserver is
EXECsp_addlinkedserver
[@server= ] 'server'
, [ @provider= ] 'provider_name'
,[ @srvproduct= ] 'product_name' [
, [ @datasrc= ] 'data_source'
[ , [ @location= ] 'location' ]
[ , [ @provstr= ] 'provider_string'
86
[ , [ @catalog= ] 'catalog' ]
Parameter Description
Server Local name used for the linked server.
Product name of the OLE DB data source. For SQL Server instances, the
product_name
product_nameis 'SQLServer'.
This is the unique programmatic identifier for the OLE DB provider. When not
provider_name specified, the provider name is the SQL Server data source. The explicit
provider_name for SQL Server is SQLNCLI (for Microsoft SQL Native Client
OLE DB Provider).
data_source This is the data source as interpreted by the OLE DB provider.
Location The location interpreted by the OLE DB provider.
provider_string The connection string specific to the OLE DB provider.
Catalog This varies from the database systems.
3. Add linked server definitions on each member server that contains the
connection information required to run distributed queries on the other
member servers. This gives a distributed partitioned view access to
data on the otherservers.
4. Defining Distributed PartitionViews:
After you create the member tables, you define a distributed partitioned view on
each member server, with each view having the same name. This
enables queries that reference the distributed partitioned view name to
run on one or more of the member servers. The system operates as if a
copy of the original table is on each member server, but each server
has only a member table and a distributed partitioned view.
Create the following distributed partitionedview:
CREATE VIEW Customers AS select statement
Queries:
1. Insert and
Display details in
into <tablename>
87
values(list of
values); select
*from<tablename>;
select sum(totalstock) 'Total Books' from BooksView where price between 25 and
100
3. Update the book price of book No=1234 from $45 to $55 at siteS3.
USE [S1]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
88
[Topic] [varchar](50) NULL,
[ISBN] ASC
) ON [PRIMARY]
GO
GO
USE [S4]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
89
[InventoryValue] [decimal](18, 0) NULL,
[StoreNo] ASC
) ON [PRIMARY]
GO
GO
USE [S4]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
) ON [PRIMARY]
90
GO
GO
FOREIGN KEY([StoreNo])
GO
GO
91
select * from s2.dbo.BookStore
92
select * from s2.dbo.Stock union
--Find the total number of books in stock where price is between $15 and $55
93
select * from s4.dbo.Stock
--Find the total number of books in stock where price is between $15 and $55
group by bv.ISBN
group by bv.ISBN
RESULT:
Thus the distributed database has been executed successfully and the output is verified
94
DATE: 07-05-2021
Aim:
To implement deadlock detection algorithm for distributed database using wait-for graph
Description:
T5 initiated at site S3
95
CODINGS:
Connected to:
varchar2(10));
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
96
SQL> insert into dd1
values('t3','x2','x7','s1');
1 row created.
1 row created.
1 row created.
1 row created.
t1 x1 x8 s1
t1 x6 x2 s2
t2 x4 x7 s2
t2 x5 s3
t3 x2 x7 s1
t4 x7 s2
t4 x8 x5 s3
t5 x3 x7 s3
8 rows selected.
SQL> ed dd1;
SQL> @dd1;
42 /
ERROR at line 3:
malformed
malformed
malformed
98
PL/SQL: Statement ignored
SQL> ed dd1;
SQL> @dd1;
42 /
ll(c) := ss.lock1;
SQL> ed dd1;
SQL> @dd1;
42 /
t1 x1 x8
t1 x6 x2
t2 x4 x7
t2 x5
t3 x2 x7
t4 x7
t4 x8 x5
t5 x3 x7
x5<-x5deadlock occured
x2<-x2deadlock occured
99
x7<-x7deadlock occured
x7<-x7deadlock occured
x7<-x7deadlock occured
x8<-x8deadlock occured
SQL> ed dd2;
SQL> @dd2;
37 /
t1 x1 x8
t3 x2 x7
SQL> ed dd3;
SQL> ed dd3;
SQL> @dd3;
40 /
ERROR at line 3:
100
ORA-06550: line 19, column 15:
malformed
malformed
malformed
malformed
SQL> ed dd3;
SQL> @dd3;
41 /
101
ERROR at line 3:
malformed
malformed
malformed
malformed
102
ORA-06550: line 28, column 1:
SQL> ed dd3;
SQL> @dd3;
41 /
t1 x6 x2
t2 x4 x7
t4 x7
x7<-x7deadlock occured
no deadlock
SQL> ed dd4;
SQL> @dd4;
37 /
ERROR at line 3:
103
PLS-00320: the declaration of the type of this expression is incomplete or
malformed
malformed
malformed
malformed
SQL> ed dd4;
SQL> @dd4;
37 /
t2 x5
t4 x8 x5
t5 x3 x7
x5<-x5deadlock occured
104
PL/SQL procedure successfully completed.
SQL> ed dd1;
SQL> @dd1;
42 /
t1 x1 x8
t1 x6 x2
t2 x4 x7
t2 x5
t3 x2 x7
t4 x7
t4 x8 x5
t5 x3 x7
x5<-x5deadlock occured
x2<-x2deadlock occured
x7<-x7deadlock occured
x7<-x7deadlock occured
x7<-x7deadlock occured
x8<-x8deadlock occured
SQL>
DD1 :
declare
cursor c1 is
FROM dd1;
105
llc_list:=c_list();
l2 c_list1:=c_list1();
tc_list:=c_list();
c integer := 0;
d integer :=0;
f integer :=0;
ss c1%rowtype;
begin
open c1;
loop
c := c+1;
ll.extend;
ll(c) := ss.loc;
f := f+1;
t.extend;
t(f) := ss.trans;
d :=d+1;
l2.extend;
l2(d) := ss.wait;
dbms_output.put_line(ss.trans||' '||ss.loc||'
106
'||ss.wait); end loop;
fori in 1 .. c loop
for j in 1 .. d loop
if(ll(i) != '-')then
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end if;
end loop;
end loop;
end;
DD2:
declare
cursor c1 is
FROM dd1
WHERE Site='s1';
llc_list:=c_list();
l2 c_list1:=c_list1();
tc_list:=c_list();
c integer := 0;
d integer :=0;
ss c1%rowtype;
107
begin
open c1;
loop
c := c+1;
ll.extend;
ll(c) := ss.loc;
d :=d+1;
l2.extend;
l2(d) := ss.wait;
end loop;
fori in 1 .. c loop
for j in 1 .. d loop
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end loop;
end loop;
end;
DD3:
declare
cursor c1 is
108
FROM dd1
WHERE Site='s2';
llc_list:=c_list();
l2 c_list1:=c_list1();
tc_list:=c_list();
c integer := 0;
d integer :=0;
e integer :=0;
ss c1%rowtype;
begin
open c1;
loop
c := c+1;
ll.extend;
ll(c) := ss.loc;
d :=d+1;
l2.extend;
l2(d) := ss.wait;
end loop;
109
fori in 1 .. c loop
for j in 1 .. d loop
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end loop;
end loop;
if (e = 0) then
end if;
end;
DD4:
declare
cursor c1 is
FROM dd1
WHERE Site='s3';
llc_list:=c_list();
l2 c_list1:=c_list1();
tc_list:=c_list();
c integer := 0;
d integer :=0;
ss c1%rowtype;
110
begin
open c1;
loop
c := c+1;
ll.extend;
ll(c) := ss.loc;
d :=d+1;
l2.extend;
l2(d) := ss.wait;
end loop;
fori in 1 .. c loop
for j in 1 .. d loop
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end loop;
RESULT:
Thus the program to execute deadlock detection algorithm for distributed database using
111