Database Management Systems Lab

Published on February 2017 | Categories: Documents | Downloads: 60 | Comments: 0 | Views: 526
of 57
Download PDF   Embed   Report

Comments

Content

www.VidyarthiPlus.in 1

Department of Computer Science & Engineering

141452– DBMS LAB
EXP.N0:1 DATA DEFINITION LANGUAGE [DDL] To execute the DATA DEFINITION LANGUAGE (DDL) commands.

AIM:

CREATING A TABLE SYNTAX: create table <table name> (column 1 datatype 1, ……., column n datatype n); EXPLANATION: Create command is used to create a table in the database. EXAMPLE: SQL> create table student (VT number, name varchar (10)); OUTPUT: Table created.

DESC COMMAND SYNTAX: desc <table name>; EXPLANATION: This command is used to view the structure of the table. EXAMPLE: SQL> desc student;

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 2

OUTPUT: NAME VT NAME NULL? TYPE NUMBER VARCHAR (10)

ALTERING A TABLE EXPLANATION: The structure of the table can be changed using this command like add new column, change the width of a datatype, change the datatype of a column. 1. MODIFY

SYNTAX: alter table <table name> modify (column datatype, …);

EXAMPLE: SQL> alter table student modify (name varchar (20)); OUTPUT: Table altered.

2. ADD / DROP

SYNTAX: alter table <table name> add/drop (column datatype, …);

EXAMPLE: SQL> alter table student add (dept varchar (20)); SQL> alter table student drop (addr); OUTPUT:

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 3

Table altered.

TRUNCATING A TABLE SYNTAX: truncate table <table name>; EXPLANATION: This command is used to delete all records stored in a table, but the structure of the table is retained. EXAMPLE: SQL> truncate table student; OUTPUT: Table truncated.

DROPPING A TABLE SYNTAX: drop table <table name>; EXPLANATION: This command is used to remove a table from the database. EXAMPLE: SQL> drop table student; OUTPUT: Table dropped.

RESULT: Thus, the data definition language commands were executed and their outputs were verified.

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 4

EXP.N0:2

DATA MANIPULATION LANGUAGE [DML]

AIM: To execute the DATA MANIPULATION LANGUAGE (DML) commands.

INSERT COMMANDS 1. INSERT A ROW WITH VALUES FOR COLUMNS IN A TABLE. SYNTAX: insert into <table name> values (value1, value2,……, value n); EXPLANATION: This insert command is used to add rows to a table in the database. EXAMPLE: SQL> insert into student values (4169, ‘rameeze’); OUTPUT: 1 row created.

2. INSERT A LARGE NUMBER OF ROWS. SYNTAX: insert into <table name> values (&value1, &value2,……, &value n); EXPLANATION: This insert command is used to add multiple rows to a table in the database. EXAMPLE: SQL> insert into student values (&vt, ‘&name’);

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 5

OUTPUT: Enter value for vt: 4169 Enter value for name: rameeze Old 1: insert into student values (&vt, ‘&name’) New 1: insert into student values (4169, ‘rameeze’) 1 row created.

SELECT COMMANDS 1. SELECT ALL ROWS FROM A TABLE. SYNTAX: select * from <table name>; EXPLANATION: This select command is used to retrieve all the values stored in the table. EXAMPLE: SQL> select * from student; OUTPUT: VT 4169 NAME RAMEEZE

2. SELECT DISTINCT ROWS FROM A TABLE. SYNTAX: select <field name> from <table name>; EXPLANATION: This select command is used to retrieve the particular field values stored in the table. EXAMPLE: SQL> select name from student; OUTPUT: NAME

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 6

RAMEEZE 3. SELECT USING WHERE COMMAND. SYNTAX: select <field name> from <table name> where <search condition>; EXPLANATION: This select command is used to retrieve the particular field values, stored in the table, which satisfy a required condition. EXAMPLE: SQL> select name from student where vt=4169; OUTPUT: NAME RAMEEZE UPDATE COMMAND SYNTAX: update <table name> set column1=expression, column 2=expression, ……, column n=expression where <search condition>; EXPLANATION: This command is used to update (changing values in) one or two columns of a row in a table. Specific rows can be updated based on some condition. EXAMPLE: SQL> update student set name=’md rameeze’ where vt =4169; OUTPUT: 1 row updated. SQL> select * from student; VT 4169 NAME MD RAMEEZE

DELETE COMMAND

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 7

SYNTAX: delete from <table name> where <search condition>; EXPLANATION: This command is used to delete a row from a table. EXAMPLE: SQL> delete from student where vt =4169; OUTPUT: 1 row deleted. SQL> select * from student; no rows selected. TRANSACTION CONTROL LANGUAGE: All changes made to the database is defined as a transaction. It is logical unit of work. The transaction can made permanent to a database only they are committed. A transaction begins with an executable SQL statement. The two transaction control commands are: 1. COMMIT 2. ROLLBACK 1. COMMIT: This command is used to make all transaction changes permanent to the database. This command erases all save point and release the transaction lock. Syntax: COMMIT SAVEPOINT: It is not a command. It is only a marker. Save point are used to divide as lengthy transaction into smaller ones. Syntax: Savepoint id;

2. ROLLBACK:

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 8

Rollback commands undo all the changes made in the current transaction. Syntax: a. Rollback b. Rollback to Save point id1; The first one will rollback (undo) the entire transaction and the last one will undo all changes made after the creation of the save point id1. DATA CONTROL LANGUAGE: Data control language, the previous user with privileges commands the database object (table, view, etc) of a user cant be accessed by another user without the permission of a user. The owner can allow other user to access his object as per his diversion the permission given by a user to another is called privilege. The Data Control Commands are: i. ii. GRANT Privilege REVOKE Privilege

Types of Privilege: A permission granted to execute the various data definition command like Create Table, Create Sequence, create session are called System Privilege. Granting System Privilege: Grant Command is used to give System Privilege to an oracle user. Syntax: GRANT system privilege TO user Example: GRANT CREATE session TO anu; GRANT CREATE table TO anu; Object Privilege: An Object Privilege enables a user to execute some commands on the database object like table view sequence etc. Some of the object privileges are i. Alter

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 9

ii. iii. iv. v. vi. vii. Syntax:

Index Insert Update Delete Select References

Grant object privilege [Object privilege] ON object to user [with grant option] Example: SQL> Grant Create session to student; SQL> Grant create table to student; SQL> Connect student/young; SQL> Connect system/managers; SQL> Create user staff identified by guru; SQL> Grant resource to staff; SQL> Connect staff/guru; SQL> Select * from staff; Staff master in a table in the user staff we first log on the staff [SQL> Connect staff/guru;] SQL> Grant select insert on staff master to student; Now log on to student and try the select command SQL> Connect student/young; SQL> Select * from staff; In this manner you can verify the following example:1. SQL> Grant select, update, delete on student-master to staff; 2. Revoking the permission: Permission granted to a user can also be taken back by the granter. This can be done by the REVOKE command. Syntax: Revoke object privilege [object privilege] ON object name from user name; Example: i. ii. RESULT: SQL> REVOKE SELECT, INSERT ON STUDENT_MASTER from staff; SQL> REVOKE SELECT ON STUDENT_MASTER from rajan;

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 10

Thus the given DML, DCL and TCL commands are successfully executed and the output is verified.

EXP.N0:3 AIM:

QUERIES IN SQL

To write and execute queries in SQL.

1. SELECT Example: select name from cust; Output: NAME hayes jones blake

2. WHERE Example: select city from cust where name= “hayes”; Output: 3. FROM Example: select name, city from cust; Output: NAME hayes jones blake britto smith CITY harrison redwood downtown mounthill harrison CITY harrison

4. RENAME Example: select borrower.loan_no as loan_id from borrower; Output: LOAN_ID 16 93

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 11

15 14 17 5. STRING OPERATIONS (a) “%”. Example: select name from cust where city like ’har%’; Output: NAME hayes smith

(b) “_”. Example: select city from cust where name like “_ _ _ _ _”; Output: CITY harrison redwood downtown harrison

6. ORDERING OF TUPLES Example: select * from loan order by amount asc; Output: LOAN NO 11 16 14 15 17 7. UNION Example: (select name from depositor) union (select name from borrower); NAME adams britto hayes jones smith 8. INTERSECTION Output: BRANCH AMOUNT 900 1100 1500 1500 2000

roundhill perryridge downtown perryridge redwood

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 12

Example: (select name from depositor) intersect (select name from borrower); Output: NAME hayes jones

9. AGGREGATE FUNCTIONS (a) AVERAGE. Example: select avg (balance) from account; Output: AVG (BALANCE) 487.5

(b) MINIMUM. Example: select min (balance) from account; Output: MIN (BALANCE) 350

(c) MAXIMUM. Example: select max (balance) from account; Output: MAX (BALANCE) 700

(d) TOTAL. Example: select total (balance) from account; Output: SUM (BALANCE) 1950 (e) COUNT.

Example: select count (balance) from account; COUNT (BALANCE) 4 10. NESTED QUERIES Example: select name from depositor where depositor.name in (select name from Output:

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 13

cust); Output: NAME hayes jones

RESULT: Thus, the queries in SQL were executed and the outputs were verified.

Ex.No:4 AIM:

VIEWS

To study the Simple View and Complex View and to execute them. Views (i) Logically represents subsets of data from one or more tables. (ii) You can present logical subsets or combinations of data by creating views of tables. A view is a logical table based on a table or another view. A view contains no data of its own but is like a window through which data from tables can be viewed or changed. The tables on which a view is based are called base tables. The view is stored as a SELECT statement in the data dictionary. Why Use Views? • To restrict data access • To make complex queries easy • To provide data independence • To present different views of the same data. Advantages of Views • Views restrict access to the data because the view can display selective columns from the table. • Views can be used to make simple queries to retrieve the results of complicated queries. For example, views can be used to query information from multiple tables without the user knowing how to write a join statement. • Views provide data independence for ad hoc users and application programs. One view can be used to retrieve data from several tables. • Views provide groups of users access to data according to their particular criteria. Simple Views versus Complex Views There are two classifications for views: simple and complex. The basic difference is related to the DML (INSERT, UPDATE, and DELETE) operations. • A simple view is one that: – Derives data from only one table – Contains no functions or groups of data – Can perform DML operations through the view • A complex view is one that: – Derives data from many tables

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 14

– Contains functions or groups of data – Does not always allow DML operations through the view – Creating a View • You embed a subquery within the CREATE VIEW statement. Syntax: CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view [(alias[, alias]...)] AS subquery [WITH CHECK OPTION [CONSTRAINT constraint]] [WITH READ ONLY [CONSTRAINT constraint]]; – • The subquery can contain complex SELECT

Example: • Create a view, EMPVU80, that contains details of employees in department 80. CREATE VIEW empvu80 AS SELECT employee_id, last_name, salary FROM employees WHERE department_id = 80; View created. • Describe the structure of the view by using the iSQL*Plus DESCRIBE command. Example: DESCRIBE empvu80 Assigning Names to Columns We Can Assign names for the various colmns in the view. * Create a view by using column aliases in the subquery. CREATE VIEW salvu50 AS SELECT employee_id ID_NUMBER, last_name NAME, salary*12 ANN_SALARY FROM employees WHERE department_id = 50; View created. (or) CREATE VIEW salvu50(ID_NUMBER,NAME,ANN_SALARY) AS SELECT employee_id , last_name ,

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 15

salary*12 FROM employees WHERE department_id = 50; View created.

• Select the columns from this view by the given alias names. Retrieving Data from a View SELECT * FROM salvu50;

Modifying a View • Modify the EMPVU80 view by using CREATE OR REPLACE VIEW clause. Add an alias for each column name. • Column aliases in the CREATE VIEW clause are listed in the same order as the columns in the subquery. CREATE OR REPLACE VIEW empvu80 (id_number, name, sal, department_id) AS SELECT employee_id, first_name || ’ ’ || last_name, salary, department_id FROM employees WHERE department_id = 80; View created. Creating a Complex View Create a complex view that contains group functions to display values from two tables. CREATE VIEW dept_sum_vu (name, minsal, maxsal, avgsal) AS SELECT d.department_name, MIN(e.salary), MAX(e.salary),AVG(e.salary) FROM employees e, departments d WHERE e.department_id = d.department_id GROUP BY d.department_name; View Created;

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 16

Creating a Complex View The example on the slide creates a complex view of department names, minimum salaries, maximum salaries, and average salaries by department. Note that alternative names have been specified for the view. This is a requirement if any column of the view is derived from a function or an expression. You can view the structure of the view by using the iSQL*Plus DESCRIBE command. Display the contents of the view by issuing a SELECT statement. SELECT * FROM dept_sum_vu; Removing a View You can remove a view without losing data because a view is based on underlying tables in the database. Syntax: DROP VIEW view; Example: DROP VIEW empvu80; View dropped.

RESULT:

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 17

Thus, the Simple view and Complex view were executed and the outputs were verified.

EXP.N0:5

HIGH LEVEL PROGRAMMING LANGUAGE EXTENSIONS FUNCTIONS AND PROCEDURES

AIM: To implement FUNCTIONS AND PROCEDURES using STRUCTURED QUERY LANGUAGE.

ALGORITHM:

1. 2. 3. 4. 5. 6. 7.

Create the function using function name. Declare the variables to be used. Begin the function. Specify the operations. Return the value to the variable declared. End. Procedure does not return value, but helps to call a function.

PROGRAM (a): SQL> create or replace function F1 (n number) return number is k number; begin k: = n*100; return k; end; / OUTPUT: function created. SQL> select F1(3) from dual; F1 (3) 300

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 18

PROGRAM (b): SQL> create or replace function F2 (a number) return char is o varchar 2(25):= ‘The number is odd’; e varchar 2(25):= ‘The number is even’; r number; begin r: = mod (a, 2); if r=0 then return e; else return o; endif; end; / OUTPUT: function created. SQL> select F2 (9) from dual; F2 (9) The number is odd. PROGRAM (c): SQL> select * from emp; NO 15 16 17 18 19 20 NAME SACHIN SAURAV RAHUL YUVRAJ DHONI GAUTAM EMPSAL 9000 9000 9000 7500 6000 5000 DEPT 6 rows 11 selected. 11 01 11 10 10

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 19

SQL>create or replace function F3 (sal number, dept number) return number is minsal number; maxsal number ; begin select MIN (empsal), MAX (empsal) into minsal, maxsal from emp where dept= dept1; if ((sal>= minsal) and (sal<= maxsal)) then return (sal); else return (0); endif; end F3; / OUTPUT: function created. SQL> set serveroutput on; SQL> declare a number; begin a: = F3 (&sal, &dept); if a=0 then dbms_output.put_line (‘Salary out of range.’); else dbms_output.put_line (‘Salary is in range and is’||a); endif; end; / OUTPUT: Enter the value for sal: 9000 Enter the value for dept.: 01 old 4 : a: = f3(&sal, &dept); new 4: a:= f3 (9000, 01); Salary is in range and is 9000. PL/SQL Procedure is successfully completed.

RESULT: Thus, the FUNCTIONS AND PROCEDURES were executed using SQL

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 20

and the outputs were verified.

Ex.No:6

FRONT END TOOLS

Aim: To study about the various front end tools to design forms and reports.

Examples Front End Tools: • • • • • Visual Basic Visual C++ Java PHP HTML

1. MICROSOFT VISUAL BASIC: Visual Basic (VB) is the third-generation event-driven programming language and integrated development environment (IDE) from Microsoft for its COM programming model. Visual Basic is relatively easy to learn and use. Visual Basic was derived from BASIC and enables the rapid application development (RAD) of graphical user interface (GUI) applications, access to databases using Data Access Objects, Remote Data Objects, or ActiveX Data Objects, and creation of ActiveX controls and objects. Scripting languages such as VBA and VBScript are syntactically similar to Visual Basic, but perform differently. A programmer can put together an application using the components provided with Visual Basic itself. Programs written in Visual Basic can also use the Windows API, but doing so requires external function declarations. The final release was version 6 in 1998. Microsoft's extended support ended in March 2008 and the designated successor was Visual Basic .NET (now known simply as Visual Basic). Language features

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 21

Like the BASIC programming language, Visual Basic was designed to be easily learned and used by beginner programmers. The language not only allows programmers to create simple GUI applications, but can also develop complex applications. Programming in VB is a combination of visually arranging components or controls on a form, specifying attributes and actions of those components, and writing additional lines of code for more functionality. Since default attributes and actions are defined for the components, a simple program can be created without the programmer having to write many lines of code. Performance problems were experienced by earlier versions, but with faster computers and native code compilation this has become less of an issue. Although programs can be compiled into native code executables from version 5 onwards, they still require the presence of runtime libraries of approximately 1 MB in size. This runtime is included by default in Windows 2000 and later, but for earlier versions of Windows like 95/98/NT it must be distributed together with the executable. Forms are created using drag-and-drop techniques. A tool is used to place controls (e.g., text boxes, buttons, etc.) on the form (window). Controls have attributes and event handlers associated with them. Default values are provided when the control is created, but may be changed by the programmer. Many attribute values can be modified during run time based on user actions or changes in the environment, providing a dynamic application. For example, code can be inserted into the form resize event handler to reposition a control so that it remains centered on the form, expands to fill up the form, etc. By inserting code into the event handler for a key press in a text box, the program can automatically translate the case of the text being entered, or even prevent certain characters from being inserted. Visual Basic can create executables (EXE files), ActiveX controls, or DLL files, but is primarily used to develop Windows applications and to interface database systems. Dialog boxes with less functionality can be used to provide pop-up capabilities. Controls provide the basic functionality of the application, while programmers can insert additional logic within the appropriate event handlers. For example, a drop-down combination box will automatically display its list and allow the user to select any element. An event handler is called when an item is selected, which can then execute additional code created by the programmer to perform some action based on which element was selected, such as populating a related list. Alternatively, a Visual Basic component can have no user interface, and instead provide ActiveX objects to other programs via Component Object Model (COM). This allows for server-side processing or an add-in module. The language is garbage collected using reference counting, has a large library of utility objects, and has basic object oriented support. Since the more common components are included in the default project template, the programmer seldom needs to specify additional libraries. Unlike many other programming languages, Visual Basic is generally not case sensitive, although it will transform keywords into a standard case configuration and force the case of variable names to conform to the case of the entry within the symbol table. String comparisons are case sensitive by default, but can be made case insensitive if so desired.

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 22

The Visual Basic compiler is shared with other Visual Studio languages (C, C++), but restrictions in the IDE do not allow the creation of some targets (Windows model DLLs) and threading models.

Characteristics Visual Basic has the following traits which differ from C-derived languages:








Multiple assignment available in C language is not possible. A = B = C does not imply that the values of A, B and C are equal. The Boolean result of "Is B = C?" is stored in A. The result stored in A would therefore be either false or true. Boolean constant True has numeric value −1.[4] This is because the Boolean data type is stored as a 16-bit signed integer. In this construct −1 evaluates to 16 binary 1s (the Boolean value True), and 0 as 16 0s (the Boolean value False). This is apparent when performing a Not operation on a 16 bit signed integer value 0 which will return the integer value −1, in other words True = Not False. This inherent functionality becomes especially useful when performing logical operations on the individual bits of an integer such as AND, OR, XOR and Not.[5] This definition of True is also consistent with BASIC since the early 1970s Microsoft BASIC implementation and is also related to the characteristics of CPU instructions at the time. Logical and bitwise operators are unified. This is unlike some C-derived languages (such as Perl), which have separate logical and bitwise operators. This again is a traditional feature of BASIC. Variable array base. Arrays are declared by specifying the upper and lower bounds in a way similar to Pascal and FORTRAN. It is also possible to use the Option Base statement to set the default lower bound. Use of the Option Base statement can lead to confusion when reading Visual Basic code and is best avoided by always explicitly specifying the lower bound of the array. This lower bound is not limited to 0 or 1, because it can also be set by declaration. In this way, both the lower and upper bounds are programmable. In more subscript-limited languages, the lower bound of the array is not variable. This uncommon trait does exist in Visual Basic .NET but not in VBScript.

2. MICROSOFT VISUAL C++ Microsoft Visual C++ (often abbreviated as MSVC or VC++) is a commercial (free version available), integrated development environment (IDE) product from Microsoft for the C, C++, and C++/CLI programming languages. It has tools for developing and debugging C++ code, especially code written for the Microsoft Windows API, the DirectX API, and the Microsoft .NET Framework.

History
Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 23

The predecessor to Visual C++ was called Microsoft C/C++. There was also a Microsoft QuickC 2.5 and a Microsoft QuickC for Windows 1.0.

16-bit versions
• • •

• • • • •



Microsoft C 1.0, based on Lattice C, was Microsoft's first C product in 1983. It was not K&R C. C 2.0 added large model support. C 3.0 was the first version developed inside Microsoft. It was extremely compatible with K&R and the later ANSI standard. It was being used inside Microsoft (for Windows and Xenix development) in early 1984. It shipped as a product in 1985. C 4.0 added optimizations and CodeView, a source level debugger. C 5.0 added loop optimizations and Huge Model (arrays bigger than 64k) support. Microsoft FORTRAN and the first 32 bit compiler for 80386 were also part of this project. C 6.0 released in 1989. It added global flow analysis, a source browser, and a new debugger, and included an optional C++ front end. C/C++ 7.0 was released in 1992. It added built-in support for C++ and MFC 1.0.[2] Visual C++ 1.0, which included MFC 2.0, was the first version of Visual C++, released in February 1993. It was Cfront 2.1 compliant[3] and available in two editions:[4] o Standard – replaced QuickC for Windows. o Professional – replaced C/C++ 7.0. Included the ability to build both DOS and Windows applications, an optimizing compiler, a source profiler, and the Windows 3.1 SDK.[3] The Phar Lap 286 DOS Extender Lite was also included.[5] Visual C++ 1.5 was released in December 1993, included MFC 2.5, and added OLE 2.0 and ODBC support to MFC.[6] It was the first version of Visual C++ that came only on CDROM. o Visual C++ 1.51 and 1.52 were available as part of a subscription service. o Visual C++ 1.52b is similar to 1.52, but does not include the Control Development Kit. o Visual C++ 1.52c was a patched version of 1.5. It is the last, and arguably most popular, development platform for Microsoft Windows 3.x. It is available through Microsoft Developer Network.

32-bit versions




Visual C++ 1.0 (original name: Visual C++ 32-bit Edition) was the first version for 32bit development. Although released when 16-bit 1.5 was available, it did not include support for OLE2 and ODBC. It was also available in a bundle called Visual C++ 16/32bit Suite, which included Visual C++ 1.5. Visual C++ 2.0, which included MFC 3.0, was the first version to be 32-bit only. In many ways, this version was ahead of its time, since Windows 95, then codenamed "Chicago", was not yet released, and Windows NT had only a small market share. As a result, this release was almost a "lost generation". Microsoft included and updated Visual C++ 1.5 as part of the 2.x releases up to 2.1, which included Visual C++ 1.52, and both 16-bit and 32-bit version of the Control Development Kit (CDK) were included. Visual C++ 2.x also supported Win32s development. It is available through Microsoft Developer

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 24

Network. There was a Visual C++ 2.0 RISC Edition for MIPS and Alpha processors, as well as a cross-platform edition for the Macintosh (68000 instruction set). o Visual C++ 2.1 and 2.2 were updates for 2.0 available through subscription. • Visual C++ 4.0, which included MFC 4.0, was designed for Windows 95 and Windows NT. To allow support of legacy (Windows 3.x/DOS) projects, 4.0 came bundled with the Visual C++ 1.52 installation CD. Updates available through subscription included Visual C++ 4.1, which came with the Microsoft Game SDK (later released separately as the DirectX SDK), and Visual C++ 4.2. Version number 3.0 was skipped to achieve version number parity between Visual C++ 4.0 and MFC 4.0.[9] [10] • Visual C++ 4.2 did not support Windows 3.x (Win32s) development. This was the final version with a cross-platform edition for the Macintosh available and it differed from the 2.x version in that it also allowed compilation for the PowerPC instruction set. [11] • Visual C++ 5.0, which included MFC 4.21, was a major upgrade from 4.2. Available in four editions: o Learning o Professional o Enterprise o RISC • Visual C++ 6.0 (commonly known as VC6), which included MFC 6.0, was released in 1998.[16] The release was somewhat controversial since it did not include an expected update to MFC. Visual C++ 6.0 is still quite popular and often used to maintain legacy projects. There are, however, issues with this version under Windows XP, especially under the debugging mode (for example, the values of static variables do not display). The debugging issues can be solved with a patch called the "Visual C++ 6.0 Processor Pack". • Visual C++ .NET 2002 (known also as Visual C++ 7.0), which included MFC 7.0, was released in 2002 with support for link time code generation and debugging runtime checks, .NET 1.0, and Visual C# and Managed C++. The new user interface used many of the hot keys and conventions of Visual Basic, which accounted for some of its unpopularity among C++ developers • Visual C++ .NET 2003 (known also as Visual C++ 7.1), which included MFC 7.1, was released in 2003 along with.NET 1.1 and was a major upgrade to Visual C++ .NET 2002. It was considered a patch to Visual C++ .NET 2002. Accordingly, the English language upgrade version of Visual Studio .NET 2003 shipped for minimal cost to owners of the English language version of Visual Studio .NET 2002. This was the last version to support Windows 95 and NT 4.0 as a target. • eMbedded Visual C++ in various versions was used to develop for some versions of the Windows CE operating system. Initially it replaced a development environment consisting of tools added onto Visual C++ 6.0. eMbedded Visual C++ was replaced as a separate development environment by Microsoft Visual Studio 2005. • Visual C++ 2005 (known also as Visual C++ 8.0), which included MFC 8.0, was released in November 2005. This version supports .NET 2.0 and dropped Managed C++ for C++/CLI. Managed C++ for CLI is still available via compiler options though. It also introduced OpenMP. With Visual C++ 2005, Microsoft also introduced Team Foundation Server. Visual C++ 8.0 has problems compiling MFC AppWizard projects that were created using Visual Studio 6.0, so maintenance of legacy projects can be continued with

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 25

• •



o o o o

the original IDE if rewriting was not feasible. Visual C++ 2005 is the last version to be able to target Windows 98 and Windows Me. SP1 version also available in Microsoft Windows SDK Update for Windows Vista. Version number: 14.00.50727.762 Visual C++ 2008 (known also as Visual C++ 9.0) was released in November 2007. This version supports .NET 3.5. Managed C++ for CLI is still available via compiler options. By default, all applications compiled against the Visual C++ 2008 Runtimes (static and dynamic linking) will only work under Windows 2000 and later. A feature pack released for VC9, later included into SP1, added support for C++ TR1 library extensions. Visual C++ 2010 (known also as Visual C++ 10.0) was released on April 12, 2010, and it is currently the latest stable release. It uses a SQL Server Compact database to store information about the source code, including IntelliSense information, for better IntelliSense and code-completion support.[22] (However, Visual C++ 2010 does not support Intellisense for C++/CLI.[23]) This version adds a modern C++ parallel computing library called the Parallel Patterns Library, partial support for C++0x, significantly improved IntelliSense, and performance improvements to both the compiler and generated code.[24] This version is built around .NET 4.0, but supports compiling to machine code. The partial C++0x support mainly consists of six compiler features[25] (lambdas, rvalue references, auto, decltype, static_assert, nullptr), and some library features (e.g. moving the TR1 components from std::tr1 namespace directly to std namespace). Variadic templates were also considered, but delayed until some future version due to lower priority which stemmed from the fact that unlike other costly-toimplement features (lambda, rvalue references), this one would benefit only a minority of library writers than the majority of compiler end users.[26] By default, all applications compiled against the Visual C++ 2010 Runtimes will only work under Windows XP SP2 and later. Beta 2 version number: 16.00.21003.01 (this is the version of compiler; the IDE itself has version number 16.00.21006.01)[27] RC version number: 16.00.30128.01 RTM version, also available in Windows SDK for Windows 7 and .NET Framework 4 (WinSdk v7.1).[28] Version number: 16.00.30319.01 SP1 version, also available in KB2519277 update to Windows SDK v7.1: 16.00.40219.01

64-bit versions
Visual Studio 2005 Standard and Professional editions have x86-64 compiler support, and Visual Studio 2008 Team Suite supports both x86-64 and IA-64. Prior to Visual C++ 2005, the Platform SDK was the only way for programmers to develop 64-bit Windows applications. The SDK included both a compiler and a Visual C++ 6.0 library for the IA64-target. Programmers who wanted the 64-bit versions of the Visual C++ .NET 2003 libraries (which are no longer available) had to contact libs7164microsoft.com.

3. JAVA

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 26

Java is a programming language originally developed by James Gosling at Sun Microsystems (now part of Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to byte code (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is a general-purpose, concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere." Java is currently one of the most popular programming languages in use, particularly for client-server web applications.[9][10] The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun relicensed most of its Java technologies under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java and GNU Class path.

Principles
There were five primary goals in the creation of the Java language: 1. 2. 3. 4. 5. It should be "simple, object-oriented and familiar" It should be "robust and secure" It should be "architecture-neutral and portable" It should execute with "high performance" It should be "interpreted, threaded, and dynamic"

Versions
Major release versions of Java, along with their release dates:
• • • • • • • •

JDK 1.0 (January 23, 1996) JDK 1.1 (February 19, 1997) J2SE 1.2 (December 8, 1998) J2SE 1.3 (May 8, 2000) J2SE 1.4 (February 6, 2002) J2SE 5.0 (September 30, 2004) Java SE 6 (December 11, 2006) Java SE 7 (July 28, 2011)

Features of Java
Java Platform
One characteristic of Java is portability, which means that computer programs written in the Java language must run similarly on any hardware/operating-system platform. This is achieved by compiling the Java language code to an intermediate representation called Java byte

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 27

code, instead of directly to platform-specific machine code. Java byte code instructions are analogous to machine code, but are intended to be interpreted by a virtual machine (VM) written specifically for the host hardware. End-users commonly use a Java Runtime Environment (JRE) installed on their own machine for standalone Java applications, or in a Web browser for Java applets. Standardized libraries provide a generic way to access host-specific features such as graphics, threading, and networking. A major benefit of using byte code is porting. However, the overhead of interpretation means that interpreted programs almost always run more slowly than programs compiled to native executables would. Just-in-Time compilers were introduced from early stages that compile byte codes to machine code during runtime. Performance Programs written in Java have a reputation for being slower and requiring more memory than those written in C.[26] However, Java programs' execution speed improved significantly with the introduction of Just-in-time compilation in 1997/1998 for Java 1.1, the addition of language features supporting better code analysis (such as inner classes, String Buffer class, optional assertions, etc.), and optimizations in the Java Virtual Machine itself, such as Hotspot becoming the default for Sun's JVM in 2000. Currently, Java 2.0 code has approximately half the performance of C code.

Automatic memory management
Java uses an automatic garbage collector to manage memory in the object lifecycle. The programmer determines when objects are created, and the Java runtime is responsible for recovering the memory once objects are no longer in use. Once no references to an object remain, the unreachable memory becomes eligible to be freed automatically by the garbage collector. Something similar to a memory leak may still occur if a programmer's code holds a reference to an object that is no longer needed, typically when objects that are no longer needed are stored in containers that are still in use. If methods for a nonexistent object are called, a "null pointer exception" is thrown.

4.HTML
HTML is a language for describing web pages.

• • • •

HTML stands for Hyper Text Markup Language HTML is not a programming language, it is a markup language A markup language is a set of markup tags HTML uses markup tags to describe web pages

HTML Tags
Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 28
HTML markup tags are usually called HTML tags

• • • •

HTML tags are keywords surrounded by angle brackets like <html> HTML tags normally come in pairs like <b> and </b> The first tag in a pair is the start tag, the second tag is the end tag Start and end tags are also called opening tags and closing tags

HTML Documents = Web Pages
• • •
HTML documents describe web pages HTML documents contain HTML tags and plain text HTML documents are also called web pages

The purpose of a web browser (like Internet Explorer or Firefox) is to read HTML documents and display them as web pages. The browser does not display the HTML tags, but uses the tags to interpret the content of the page:

Editing HTML
HTML can be written and edited using many different editors like Dreamweaver and Visual Studio. However, in this tutorial we use a plain text editor (like Notepad) to edit HTML. We believe using a plain text editor is the best way to learn HTML.

.HTM or .HTML File Extension?
When you save an HTML file, you can use either the .htm or the .html file extension. There is no difference, it is entirely up to you.

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 29

Result: Thus the front-end languages like VB, VC++, Java, and HTML are studied.

Ex. no: 7

FORMS- PAYROLL PROCESSING SYSTEMS

AIM: To implement the operations of PAYROLL PROCESSING SYSTEM using the visual basic as front end and oracle as back end to design a forms..

PROCEDURE: 1. Collect the details of how the program is expected by the user and also the atmosphere in which it is going to work. 2. Collect the user requirement. Develop a sketch of the program about how it is going to appear in its final design. 3. Implement the various diagram carefully, based on which the entire project design is going to be developed. 4. Assign the values as required by the program control settings. 5. In the component diagram, using the update code command we generate the code for the required program. 6. Thus the program is implemented successfully. SQL TABLE: SQL>CREATE TABLE_DETAIL(EMPID NUMBER(5) CONSTRAINT CON PRIMARY KEY,EMPNAME VARCHAR2(15), DESIGNATION VARCHAR2(20), DEPARTMENT VARCHAR2(20), ADDRESS VARCHAR(20), BASICPAY NUMBER(10,2), PF NUMBER(10,2) HRA NUMBER(10,2),INTAX NUMBER(10,2),TOTDED NUMBER(10,2),GROSSALRY NUMBER(10,2), NETPAY NUMBER(10,2)); Table created.

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 30

CODING: FORM 1: Dim db As Database Dim rs As Recordset Dim PF As Integer Dim HRA As Integer Dim DA As Integer Dim GROSSPAY As Integer Dim NETPAY As Integer Dim TOTDED As Integer Dim TAX As Integer Private sub cmdexit_Click() Unload Me End sub Private sub cmdfirst_Click() rs.MoveFirst txteno.Text=rs(0) txtename.Text=rs(1) txtdes.Text=rs(“DESINATION”) txtdept.Text=rs(“DEPARTMENT”) txtbasic.Text=rs(“BASICPAY”) End sub Private sub cmdlast_Click() rs.MoveLast txteno.Text=rs(0) txtename.Text=rs(1) txtdes.Text=rs(“DESINATION”) txtdept.Text=rs(“DEPARTMENT”) txtbasic.Text=rs(“BASICPAY”) End sub Private sub cmdnew_Click() txteno.Text=”” txtename.Text=”” txtdes.Text=””

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 31

txtdept.Text=”” txtbasic.Text=”” rs.AddNew txteno.SetFocus End sub Private sub cmdnext_Click() rs.MoveNext If rs.EOF Then MsgBox”Record pointer is in the last record” rs.MoveFirst Else txteno.Text=rs(0) txtename.Text=rs(1) txtdes.Text=rs(“DESINATION”) txtdept.Text=rs(“DEPARTMENT”) txtbasic.Text=rs(“BASICPAY”) End If End sub Private sub cmdpayroll_Click() Form2.Show End sub Private sub cmdprev_Click() rs.MovePrevious If Not rs.BOf Then txteno.Text=rs(0) txtename.Text=rs(1) txtdes.Text=rs(“DESINATION”) txtdept.Text=rs(“DEPARTMENT”) txtbasic.Text=rs(“BASICPAY”) Else MsgBox”Record pointer is in the first record” End If End sub Private sub cmdsave_Click() If (Val(txtbasic.Text)<5000)Then*0.1 HRA=Val(txtbasic.Text) *0.1 DA=Val(txtbasic.Text) *0.3 MA=100 PF=600 TAX=Val(txtbasic.Text) *0.1 End If If (Val(txtbasic.Text)>=5000) And Val(txtbasic.Text)<8000) Then

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 32

HRA=Val(txtbasic.Text) *0.15 DA=Val(txtbasic.Text) *0.4 MA=200 PF=700 TAX=Val(txtbasic.Text) *0.15 End If If(Val(txtbasic.Text)>=8000) Then HRA=Val(txtbasic.Text) *0.2 DA=Val(txtbasic.Text) *0.5 MA=300 PF=800 TAX=Val(txtbasic.Text) *0.2 End If GROSSPAY= Val(txtbasic.Text)+HRA+DA+MA NETPAY= GROSSPAY-(PF+TAX) rs.AddNew rs(0)= Val(txteno.Text) rs(1)= Trim(txtename.Text) rs(2)= Trim(txtdes.Text) rs(3)= Trim(txtdept.Text) rs(4)= Val(txtbasic.Text) rs(5)= DA rs(6)= HRA rs(7)= PF rs(8)= MA rs(9)= GROSSPAY rs(10)= NETPAY rs(11)= TAX rs.Update MsgBox”Record updated successfully” txteno.Text=”” txtename.Text=”” txtdes.Text=”” txtdept.Text=”” txtbasic.Text=”” End sub

Private sub Form_Load Set db = OpenDatabase(“E_DETAIL”,False,Fasle, ”odbc;uidvt4193;pwd=vt4193”) Set rs =db.OpenRecordset(“select*from E_DETAIL”,dbOpenDynaset) MsgBox”Successfully connected with the Database”,vbInformation,”Sucessful” End sub FORM2:

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 33

Dim db As Database Dim rs As Recordset Private sub cmdexit_Click() Load Form1 Unload Me End sub Private sub cmdnext_Click() If(Combo1.ListIndex -1)>=0 Then Combo1.ListIndex = Combo1.ListIndex -1 display Else MsgBox ”This is the first record” End If End sub Private sub cmdprev_Click() If(Combo1.ListIndex +1)>=0 Then Combo1.ListIndex = Combo1.ListIndex +1 display Else MsgBox ”This is the last record” End If End sub Private sub Form_Load() Set db = OpenDatabase(“E_DETAIL”,False,Fasle, ”odbc;uidvt4202;pwd=vt4202”) Set rs =db.OpenRecordset(“select*from E_DETAIL order by EMPID”) rs.MoveFirst Combo1.Clear Do While Not rs.EOF Combo1.AddItem rs(0) rs.MoveNext Loop Combo1.ListIndex=0 End sub Sub display() txtename.Text=rs(1) txtdes.Text=rs(2) txtdept.Text=rs(3) txtbasic.Text=rs(4) txtda.Text=rs(5) txthra.Text=rs(6)

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 34

txtma.Text=rs(7) txtpf.Text=rs(8) txttax.Text=rs(9) txtgross.Text=rs(10) txtnetpay.Text=rs(11) End sub Private sub combo1_Click() rs.MoveFirst rs.FindFirst(“EMPID=”& val(Combo1.Text)) display End sub Form 1:

Form 2:

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 35

RESULT: Thus, the payroll processing system using VB was implemented. EXP.N0:8 AIM: To create TRIGGERS on the database using SQL. TRIGGERS

ALGORITHM: • Begin by creating the trigger, specifying the trigger name. • Specify whether the operation is delete/insert on rows or every statement.

• Declare the variables. • Assign the new variables to those in tables.

• •

Specify the operation to be performed in the trigger. End.

PROGRAM (a): INPUT: EMPLOY EMPNO 10 11 12 SALARY 900 1000 1200 SALDET EMPNO 10 DEPT 11 TOTAL 900

SQL> create trigger triplet after update of salary on employ for each row

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 36

begin update saldet set total = total+1500 where empno =:new.empno; end; / OUTPUT: trigger created. SQL> update employ set salary=1000 where empno=10; 1 row updated. EMPLOY EMPNO 10 11 12 SALARY 1000 1000 1200 SALDET EMPNO 10 PROGRAM (b): SQL> create or replace trigger second before update on employ for each row begin if :new.sal>1000 or :new.dept =10; then raise_application_error (-20001,’You are not allowed to insert.’); end if; end; / OUTPUT: trigger created. SQL> update employ set salary =1200 where dept =10; Error at line 1: ORA -20001: You are not allowed to insert. DEPT 11 TOTAL 2400

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 37

PROGRAM (c): INPUT: STUDENT VT 4170 NAME Raja MARK1 60 MARK2 73

SQL>create or replace trigger first before update on student for each row declare m1 number(10); m2 number(10); begin m1:=:new.mark1; m2:=:new.mark2; if m1> m2 then raise_application_error (-20001,’mark1 should be less than mark2’); end if; end; /

OUTPUT: trigger created. SQL> update student set mark1 =80 where VT=4170;

Error at line 1: ORA -20001: mark1 should be less than mark2.

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 38

RESULT: Thus, the TRIGGERS were executed using SQL and the outputs were verified. Ex.No:9 MENU DESIGN

Aim: To implement the operation of a menu design using the vc++ as a front end and oracle as bank end.

ALGORITHM Step 1: Collect the details of how the program is expected from the user and develop the front end using Visual C++. Step 2: Step 3: Collect the user requirements. Develop the sketch on the program. Implement the various diagrams carefully, based on which the entire project design is going to be developed. Step 4: Thus the program is implemented successfully.

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 39

Program: // ex14aView.cpp : implementation of the CEx14aView class // #include "stdafx.h" #include "ex14a.h" #include "ex14aDoc.h" #include "ex14aView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = FILE ; #endif ///////////////////////////////////////////////////////////////////////////// // CEx14aView IMPLEMENT_DYNCREATE(CEx14aView, CView) BEGIN_MESSAGE_MAP(CEx14aView, CView) //{{AFX_MSG_MAP(CEx14aView) ON_COMMAND(ID_DRAW_CIRCLE, OnDrawCircle) ON_UPDATE_COMMAND_UI(ID_DRAW_CIRCLE, OnUpdateDrawCircle) ON_COMMAND(ID_DRAW_PATTERN, OnDrawPattern) ON_UPDATE_COMMAND_UI(ID_DRAW_PATTERN, OnUpdateDrawPattern) ON_COMMAND(ID_DRAW_SQUARE, OnDrawSquare) ON_UPDATE_COMMAND_UI(ID_DRAW_SQUARE, OnUpdateDrawSquare) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CEx14aView construction/destruction CEx14aView::CEx14aView() : m_rect(0, 0, 100, 100) { m_bCircle = TRUE; m_bPattern = FALSE;

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 40

} CEx14aView::~CEx14aView() { } BOOL CEx14aView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CEx14aView drawing void CEx14aView::OnDraw(CDC* pDC) { CBrush brush(HS_BDIAGONAL, 0L); // brush with diagonal pattern if (m_bPattern) { pDC->SelectObject(&brush); } else { pDC->SelectStockObject(WHITE_BRUSH); } if (m_bCircle) { pDC->Ellipse(m_rect); } else { pDC->Rectangle(m_rect); } pDC->SelectStockObject(WHITE_BRUSH); // Deselects brush // if selected } ///////////////////////////////////////////////////////////////////////////// // CEx14aView diagnostics #ifdef _DEBUG void CEx14aView::AssertValid() const { CView::AssertValid(); }

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 41

void CEx14aView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CEx14aDoc* CEx14aView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx14aDoc))); return (CEx14aDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CEx14aView message handlers void CEx14aView::OnDrawCircle() { m_bCircle = TRUE; m_rect += CPoint(25, 25); InvalidateRect(m_rect); } void CEx14aView::OnUpdateDrawCircle(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bCircle); } void CEx14aView::OnDrawPattern() { m_bPattern ^= 1; } void CEx14aView::OnUpdateDrawPattern(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_bPattern); } void CEx14aView::OnDrawSquare() { m_bCircle = FALSE; m_rect += CPoint(25, 25); InvalidateRect(m_rect); } void CEx14aView::OnUpdateDrawSquare(CCmdUI* pCmdUI) {

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 42

pCmdUI->Enable(m_bCircle); } Result: Thus the operations of a menu design using the vc++ as a front end and oracle as bank end as implemented and verified successfully. Ex.No:10 REPORTS - BANKING SYSTEM

AIM To implement the operation of a banking system using the vb on front end and oracle as bank end.

ALGORITHM Step 1 : Collect the details of how the program is expected by the user and also the atmosphere in which it is going to work. Step 2 : Step 3 : Collect the user requirements. Develop the sketch on the program. Implement the various diagrams carefully, based on which the entire project design is going to be developed. Step 4 : Thus the program is implemented successfully.

SQL TABLE Create table det1(name varchar(20),acno number,addr varchar(20),actype varchar(20),amt number,pass varchar(20));

PROGRAM Dim db As Database Dim rec As Recordset Private Sub accept_Click() If Combo2.Text = "deposit" Then Label10.Caption = Val(Label10.Caption) + Val(Text6.Text) rec.Fields("amt") = Val(Label10.Caption) rec.Update

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 43

Else If Combo2.Text = "transaction" Then Form4.Show Else If Val(Label10.Caption) >= 501 Then If Val(Label10.Caption) - Val(Text6.Text) >= 500 Then Label10.Caption = Val(Label10.Caption) - Val(Text6.Text) rec.Update Else MsgBox "min amt is 500", vbCritical, "below 500" End If Else MsgBox "min amt is 500", vbCritical, "below 500" End If End If End If accept.Enabled = False End Sub Private Sub cmdtra_Click() rec.MoveFirst Fratrans.Visible = Not Fratrans.Visible End Sub Private Sub cmdview_Click() fraview.Visible = Not fraview.Visible showrec End Sub Private Sub Combo1_Click() rec.MoveFirst Do While (rec.EOF = False) If (StrComp(rec.Fields("acno"), Combo1.Text) = 0) Then Label10.Caption = rec.Fields("amt") End If rec.MoveNext Loop accept.Enabled = True End Sub Private Sub showrec() clear Text1.Text = rec.Fields("name") Text2.Text = rec.Fields("acno") Text3.Text = rec.Fields("addr") Text4.Text = rec.Fields("actype")

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 44

Text5.Text = rec.Fields("amt") End Sub Private Sub first_Click() rec.MoveFirst showrec End Sub Private Sub Form_Load() Set db = OpenDatabase("bank", False, False, "odbc:uid=scott;pwd=tiger;dsn=bank") Set rec = db.OpenRecordset("select * from det1") MsgBox ("successfully connectted") With rec .MoveFirst Do While Not .EOF Combo1.AddItem .Fields(1) Combo2.AddItem "deposit" Combo2.AddItem "withdraw" Combo2.AddItem "transaction" .MoveNext Loop End With fraview.Visible = False Fratrans.Visible = False End Sub Private Sub last_Click() rec.MoveLast showrec End Sub Private Sub next_Click() rec.MoveNext If rec.EOF = True Then MsgBox "last record", vbCritical rec.MoveLast End If showrec End Sub Private Sub previous_Click() rec.MovePrevious If rec.BOF = True Then MsgBox "first record", vbCritical rec.MoveFirst

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 45

End If showrec End Sub Private Sub clear() Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" Text5.Text = "" End Sub FORM 2 Dim db As Database Dim rec As Recordset Dim rec1 As Recordset Private Sub Command1_Click() Form3.Show End Sub Private Sub Command3_Click() Unload Me End Sub Private Sub Form_Load() Set db = OpenDatabase("bank", False, False, "odbc:uid=scott;pwd=tiger;dsn=bank") Set rec = db.OpenRecordset("select * from det1") MsgBox ("successfully connectted") End Sub Private Sub login_Click() Do While Not rec.EOF If rec.Fields("name") = Text1.Text And rec.Fields("pass") = Text2.Text Then If rec.Fields("acno") = Text3.Text Then Unload Me Form1.Show Exit Sub End If MsgBox "Accout no is not correct", vbCritical End If rec.MoveNext Loop MsgBox "user name or password is not correct", vbCritical Text1.Text = ""

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 46

Text2.Text = "" Text3.Text = "" Text1.SetFocus End Sub

FORM 3 Dim db As Database Dim rec As Recordset Private Sub Add_Click() rec.AddNew rec(0) = Text1.Text rec(1) = Text2.Text rec(2) = Text3.Text rec(3) = Text4.Text rec(4) = Text5.Text rec(5) = Text6.Text rec.Update MsgBox "record updated", vbInformation, "ok" Unload Me End Sub Private Sub Command1_Click() Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" Text5.Text = "" Text6.Text = "" rec.AddNew End Sub Private Sub Form_Activate() Text1.SetFocus End Sub Private Sub Form_Load() Set db = OpenDatabase("bank", False, False, "odbc:uid=scott;pwd=tiger;dsn=bank") Set rec = db.OpenRecordset("select * from det1") MsgBox ("successfully connectted") End Sub FORM 4

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 47

Dim db As Database Dim rec As Recordset Dim a As Integer Private Sub Command1_Click() Do While Not rec.EOF If (StrComp(rec.Fields("acno"), Val(Text1.Text)) = 0) Then If (rec.Fields("amt") >= 501) Then a = rec.Fields("amt") - Val(Text3.Text) If (a >= 501) Then rec.Fields("amt") = rec.Fields("amt") - Text3.Text rec.Update Do While Not rec.EOF If (StrComp(rec.Fields("acno"), Val(Text2.Text)) = 0) Then rec.Fields("amt") = rec.Fields("amt") + Val(Text3.Text) rec.Update End If rec.MoveNext Loop Else MsgBox "access denied", vbCritical, "below 500" End If Else MsgBox "access denied", vbCritical, " below 500" End If MsgBox "transaction successfully completed" End If rec.MoveNext Loop End Sub Private Sub Form_Load() Set db = OpenDatabase("bank", False, False, "odbc:uid=scott;pwd=tiger;dsn=bank") Set rec = db.OpenRecordset("select * from det1") MsgBox ("successfully connectted") End Sub

FORM 1:

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 48

FORM 2:

FORM 3:

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 49

FORM 4:

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 50

RESULT: Thus, the Banking management system using VB was implemented.

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 51

EXTRA PROGRAMS

AGGREGATE FUNCTIONS
AIM:
To study the AGGREGATE FUNCTIONS and to execute them.

GROUP FUNCTIONS
Unlike single-row functions, group functions operate on sets of rows to give one result per group. These sets may be the whole table or the table split into groups.

Types of Group Functions

• AVG • COUNT
Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 52

• MAX • MIN • STDDEV • SUM • VARIANCE
Function Description
Each of the functions accepts an argument. The following table identifies the options that you can use in the syntax:

INPUT: EMPLOYEES EMPNAME
DEPARTMENT_ID JOB_ID

SALARY

Group Functions Syntax
SELECT [column,] group_function(column), ... FROM table [WHERE condition] [GROUP BY column] [ORDER BY column];

Guidelines for Using Group Functions
• DISTINCT makes the function consider only nonduplicate values; ALL makes it consider every value including duplicates. The default is ALL and therefore does not need to be specified.

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 53

• The data types for the functions with an expr argument may be CHAR, VARCHAR2, NUMBER, or DATE. • All group functions ignore null values. To substitute a value for null values, use the NVL, NVL2, or COALESCE functions. • The Oracle server implicitly sorts the result set in ascending order when using a GROUP BY clause. To override this default ordering, DESC can be used in an ORDER BY clause.

You can use the MAX and MIN functions for any data typ. EXAMPLE The following example displays the employee last name that is first and the employee last name that is the last in an alphabetized list of all employees.
SELECT MIN(last_name), MAX(last_name) FROM employees;

Note: AVG, SUM, VARIANCE, and STDDEV functions can be used only with numeric data types.

THE COUNT FUNCTION
The COUNT function has three formats: 1. •COUNT(*) 2. • COUNT(expr) 3. • COUNT(DISTINCT expr)
Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 54

1. COUNT(*) returns the number of rows in a table that satisfy the criteria of the SELECT statement, including duplicate rows and rows containing null values in any of the columns. If a WHERE clause is included in the SELECT statement, COUNT(*) returns the number of rows that satisfies the condition in the WHERE clause.

COUNT(*) returns the number of rows in a table.
EXAMPLE SELECT COUNT(*) FROM employees WHERE department_id = 50; 2. In contrast, COUNT(expr) returns the number of non-null values in the column identified by expr. EXAMPLE Display the number of department values in the EMPLOYEES table. SELECT COUNT(department_id) FROM employees; 3. COUNT(DISTINCT expr) returns the number of unique, non-null values in the column identified by expr. EXAMPLE SELECT COUNT(DISTINCT department_id) FROM employees;

GROUP FUNCTIONS AND NULL VALUES
All group functions ignore null values in the column. EXAMPLE SELECT AVG(commission_pct) FROM employees;

Using the NVL Function with Group Functions
The NVL function forces group functions to include null values. EXAMPLE
SELECT AVG(NVL(commission_pct, 0)) FROM employees;

The GROUP BY Clause
You can use the GROUP BY clause to divide the rows in a table into groups. You can then use the group functions to return summary information for each group. In the syntax: SELECT column, group_function(column) FROM table

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 55

[WHERE condition] [GROUP BY group_by_expression] [ORDER BY column]; group_by_expression specifies columns whose values determine the basis for grouping rows. EXAMPLE SELECT department_id, AVG(salary) FROM employees GROUP BY department_id ; When using the GROUP BY clause, make sure that all columns in the SELECT list that are not group functions are included in the GROUP BY clause.

USING THE GROUP BY CLAUSE ON MULTIPLE COLUMNS
EXAMPLE
SELECT department_id dept_id, job_id, SUM(salary) FROM employees GROUP BY department_id, job_id ;

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 56

The WHERE clause cannot be used to restrict groups. The SELECT statement on the slide results in an error because it uses the WHERE clause to restrict the display of average salaries of those departments that have an average salary greater than $8,000.You can correct the slide error by using the HAVING clause to restrict groups. EXAMPLE SELECT department_id, AVG(salary) FROM employees HAVING AVG(salary) > 8000 GROUP BY department_id;

THE HAVING CLAUSE
You use the HAVING clause to specify which groups are to be displayed, and thus, you further restrict the groups on the basis of aggregate information. In the syntax: SELECT column, group_function FROM table [WHERE condition] [GROUP BY group_by_expression] [HAVING group_condition] [ORDER BY column]; group_condition restricts the groups of rows returned to those groups for which the specified condition is true. The Oracle server performs the following steps when you use the HAVING clause: 1. Rows are grouped. 2. The group function is applied to the group. 3. The groups that match the criteria in the HAVING clause are displayed. The HAVING clause can precede the GROUP BY clause, but it is recommended that you place the GROUP BY clause first because that is more logical. Groups are formed and group functions are calculated before the HAVING clause is applied to the groups in the SELECT list.

NESTING GROUP FUNCTIONS
Group functions can be nested to a depth of two.

EXAMPLE Display the maximum average salary.
SELECT MAX(AVG(salary)) FROM employees GROUP BY department_id;

Copyright : VidyarthiPlus.in

www.VidyarthiPlus.in 57

RESULT:
Thus, the AGGREGATE FUNCTIONS were executed and the outputs were verified.

Copyright : VidyarthiPlus.in

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close