You are on page 1of 81

INTRODUCTION TO SQL SQL (structured query language) is a database computer language designed for the retrieval and management

of data in relational database systems (RDBMS), database scheme creation and modification, and database object access control management. FEATURES OF SQL SQL is both an easy to-understand language and a comprehensive tool for managing data. High-level .English-like structure
Interactive, ad hoc queries

Programmatic database access Multiple views of data Complete database language Dynamic data definition
Client/server architecture

TYPES OF SQL COMMANDS SQL is used to control all of the functions that a DBMS provides for its users, including: Data definition, SQL lets a user define the structure and organization of the stored data and relationship among the stored data items. Data retrieval, SQL allows a user or an application program to retrieve stored data from the database and use it. Data manipulation, SQL allows a user or an application program to update the database by adding new data, removing old data, and modifying previously stored data. Access control, SQL can be used to restrict a users ability to retrieve, add, and modify data, protecting stored data against unauthorized access. Data sharing, SQL is used to coordinate data sharing by concurrent users, ensuring that they do not interface with one another. Data integrity, SQL defines integrity constraints in the database, protecting it from corruption due to inconsistent updates or system failures.

EX.NO: DATE: DATA DEFINITION LANGUAGES (DDL) COMMANDS A Data Definition Language (DDL) statement are used to define the database structure or schema Aim: To study and execute the DDL commands in RDBMS. DDL commands: CREATE ALTER DROP RENAME TRUNCATE SYNTAXS OF COMMANDS CREATE TABLE: To make a new database, table, index, or stored query. A create statement in SQL creates an object inside of a relational database management system (RDBMS). CREATE TABLE table_name ( Column_name1 data_type, Column_name2 data_type ); ALTER A TABLE: To modify an existing database object. Alter the structure of the database. To add a column in a table ALTER TABLE table_name ADD column_name datatype; To delete a column in a table ALTER TABLE table_nmae DROP column column_nmae; DROP TABLE:

Delete Objects from the Database DROP TABLE table_name; TRUNCATE TABLE: Remove all records from a table, including all spaces allocated for the records are removed. TRUNCATE TABLE table name;

EXERCISE: 1. Create a database table named branch using DDL commands. SQL> create table Branch (b_idvarchar2 (6), b_namevarchar2 (15), b_cityvarchar2 (20), b_assertsnumber2 (20); Table created.

SQL> desc branch; NAME NULL? TYPE

----------------------------------------------------------------------------------B_ID B_NAME B_CITY B_ASSERTS VARCHAR2 (6) VARCHAR2 (15) VARCHAR2 (20) NUMBER (20)

2. Create a database table named employee using DDL commands. SQL> create table employee (e_idvarchar2(6) ,e_namevarchar2(15) , e_f_namevarchar2(20) ,e_f_namevarchar2(15),doj date, e_dept varchar2(20),e_tele_no number(20),b_id varchar2(6)); Table created.

SQL> desc employee; NAME NULL? TYPE

----------------------------------------------------------------------------------E_ID E_NAME VARCHAR2 (6) VARCHAR2 (15)

E_F_NAME DOJ E_DEPT E_TABLE_NO B_ID

VARCHAR2 (20) DATE VARCHAR2 (20) NUMBER (20) VARCHAR2 (6)

3. Set a primary key as employee_id for employee database using alter command SQL>alter table employee add (constraints p2 primary key(e_id); Table created. SQL>desc employee; NAME NULL? TYPE

----------------------------------------------------------------------------------E_ID E_NAME E_F_NAME DOJ E_DEPT E_TABLE_NO B_ID NOT NULL VARCHAR2 (6) VARCHAR2 (15) VARCHAR2 (20) DATE VARCHAR2 (20) NUMBER (20) VARCHAR2 (6)

4. Set a primary key as branch_id for branch database using alter command SQL>alter table branch add (constraints p1 primary key (b_id); Table altered. SQL>desc branch; NAME NULL? TYPE

----------------------------------------------------------------------------------B_ID B_NAME B_CITY NOT NULL VARCHAR2 (6) VARCHAR2 (15) VARCHAR2 (20)

B_ASSERTS

NUMBER (20)

5. Add a column name doc in the branch database using DDL commands. SQL>alter table branch add (doc date); Table altered. SQL>desc branch; NAME NULL? TYPE

----------------------------------------------------------------------------------B_ID B_NAME B_CITY B_ASSERTS DOC NOT NULL VARCHAR2 (6) VARCHAR2 (15) VARCHAR2 (20) NUMBER (20) DATE

6. DROP any one table in the database using the DDl commands.

SQL>drop table branch; Table dropped.

RESULT Thus the DDL commands were studied and executed in RDBMS.

EX.NO: DATE: DATA MANIPULATION LANGUAGE (DML) COMMANDS Data manipulation language allows the users to query and manipulate data in existing schema in object. It allows following data to insert, delete, update and recovery data in schema object. AIM: To study DML and DCL commands in RDBMS. DML COMMANDS: INSERT UPDATE DELETE SELECT QUERY: Query is a statement in the DML that request the retrieval of data from database. The portion of the DML used in a Query is called Query language. The SELECT statement is used to query a database SYNTAX OF COMMANDS INSERT: Values can be inserted into table using insert commands. There are two types of insert commands. They are multiple value insert commands (using & symbol) single value insert command (without using &symbol) Syntax: INSERT INTO table_name VALUES (value1, value2, value3,..); (OR) INSERT INTO table_name VALUES(value1,value2,value3,..); UPDATE: This allows the user to update the particular column value using the where clause condition. Syntax: UPDATE<tablename>SET<col1=value>WHERE<col=value>; (column1, column2, column3,.)

DELETE: This allows you to delete the particular column values using where clause condition. Syntax: DELETE FROM<tablename>WHERE<condition>; SELECT: The select statement is used to query a database .This statement is used to retrieve the information from the database. The SELECT statement can be used in many ways. They are:
1. Selecting some columns :

To select specified number of columns from the table the Following command is used. Syntax: SELECT column name FROM table_name; 2. Query All Columns: To select all columns from the table * is used instead of column names. Syntax: SELECT * FROM table_name; 3. Select using DISTINCT: The DISTINCT keyword is used to return only different values (i.e. ) this command does not select the duplicate values from the table . Syntax: SELECT DISTINCT column name(s) FROM table_name; 4. Select using IN: If you want to get the rows which contain certain values, the best way to do it is to use the IN conditional expression. Syntax: SELECT column name(s) FROM table_name WHERE Column name IN (value1, value2,, value n); 5. Select using BETWEEN: BETWEEN can be used to get those items that fall within a range.

Syntax: SELECT column name FROM table_name WHERE Column name BETWEEN value1 AND value2; 6. Renaming: The select statement can be used to rename either column or the entire Table. Syntax: Renaming a column: SELECT column name AS new name FROM table_name; Renaming a table: SELECT column name FROM table_name AS newname; 7. Sorting: The select statement with the order by Clause is used to sort the contents Table either in ascending or descending order. Syntax: SELECT column name FROM table_name WHERE Condition ORDER BY column name ASC/DESC; 8. To Select by matching some patterns: The select statement along with like clause I is used to match strings. The like condition is used to specify a search pattern in a column. Syntax: SELECT column name FROM table_name WHERE Column name LIKE % or-; %: Matches any sub string. - : Matches a single character. 9. SELECT INTO statement: The SELECT INTO statement is most often used to create backup copies of tables or for archiving records. Syntax: SELECT Column_name(s) INTO variable_name(s) FROM table_name

WHERE condition. 10. To Select NULL values: We can use the SELECT statement to select the null values also. For retrieving roes where some of the columns have been defined as NULLs there is a special comparison operator of the form IS [NOT] NULL. The syntax is: SELECT column name FROM table_name WHERE Column name IS NULL;

11. Select using AND, OR, NOT: We can combine one or more conditions in a SELECT statement using the logical operators AND, OR, NOT. Syntax: SELECT column name FROM table_name WHERE Condition1 LOGICAL OPERATOR condition2; EXERCISE: SQL> create table student (idno number,name varchar(10),branch varchar(6)); Table created. SQL> desc student; NAME NULL? TYPE

-------------------------------------------------------------------------------IDNO NAME BRANCH NUMBER VARCHAR2 (10) VARCHAR2 (6)

SQL> insert into student (name, degree, branch, idno) values ('ASHOK','BE','CSE', 01); 1 row created. SQL> insert into student values (02,'BHAVANA','CSE','BE'); 1 row created.

SQL> insert into student values (&idno,&name,&branch,&degree); Enter value for idno: 03 Enter value for name: 'CAVIN' Enter value for branch: 'CSE' Enter value for degree: 'BE' Old 1: insert into student values(&idno,&name,&branch,&degree) New 1: insert into student values(03,'CAVIN','CSE','BE') 1 row created. SQL> / Enter value for idno: 04 Enter value for name: 'DANNY' Enter value for branch: 'IT' Enter value for degree: 'BE' old 1: insert into student values(&idno, &name, &branch, &degree) new 1: insert into student values(04,'DANNY','IT','BE') 1 row created. SQL> select * from student; IDNO NAME BRAN DEGREE

-----------------------------------------------------------1 ASHOK CSE BE CSE CSE IT BE BE BE

2 BHAVANA 3 CAVIN 4 DANNY

SQL> update student set degree='B.TECH' where branch='IT'; 2 rows updated.

SQL> select * from student; IDNO NAME BRAN DEGREE

--------------------------------------------------------------1 2 3 4 5 ASHOK BHAVANA CAVIN DANNY HARRY CSE CSE CSE IT IT BE BE BE B.TECH B.TECH

SQL> delete from student where idno=5; 1 row deleted.

CREATING TABLES WITH CONSTRAINTS: NOT NULL SQL> select * from student; IDNO NAME BRAN DEGREE

--------------------------------------------------------------1 2 3 4 ASHOK BHAVANA CAVIN DANNY CSE CSE CSE IT BE BE BE B.TECH

SQL> create table staff (idno number (4) not null, name varchar(10),branch varchar(6)); Table created. SQL> desc staff; NAME NULL? TYPE

--------------------------------------------------------------------------------

IDNO NAME BRANCH

NOT NULL NUMBER (4) VARCHAR2 (10) VARCHAR2 (6)

SQL> insert into staff values (&idno,&name,&branch); Enter value for idno: 1 Enter value for name: 'ABILASH' Enter value for branch: 'CSE' Old 1: insert into staff values(&idno,&name,&branch) New 1: insert into staff values(1,'ABILASH','CSE') 1 row created. SQL> / Enter value for idno: Enter value for name: 'BENNY' Enter value for branch: 'IT' Old 1: insert into staff values(&idno,&name,&branch) New 1: insert into staff values(,'BENNY','IT') insert into staff values(,'BENNY','IT') * ERROR at line 1: ORA-00936: missing expression UNIQUE SQL> create table employee(rollno number unique, name varchar(10),salary number); Table created. SQL> desc employee; NAME NULL? TYPE

---------------------------------------------------------------------------------ROLLNO NAME SALARY NUMBER VARCHAR2 (10) NUMBER

SQL> insert into employee values (&rollno,&name,&salary); Enter value for rollno: 1 Enter value for name: 'anton' Enter value for salary: 10290 Old 1: insert into employee values(&rollno,&name,&salary) New 1: insert into employee values(1,'anton',10290) 1 row created. SQL> / Enter value for rollno: 1 Enter value for name: 'aaron' Enter value for salary: 32212 Old 1: insert into employee values(&rollno,&name,&salary) New 1: insert into employee values(1,'aaron',32212) insert into employee values(1,'aaron',32212) * ERROR at line 1: ORA-00001: unique constraint (SCOTT.SYS_C001265) violated

PRIMARY KEY SQL> create table cars (model number primary key,name varchar(10),cost number(6)); Table created. SQL> desc cars; NAME NULL? TYPE

--------------------------------------------------------------------------------------MODEL NAME COST NOT NULL NUMBER VARCHAR2 (10) NUMBER (6)

SQL> insert into cars values (&model,&name,&cost); Enter value for model: 1098 Enter value for name: 'omni' Enter value for cost: 200000
5

Old 1: insert into cars values (&model,&name,&cost) New 1: insert into cars values (1098,'omni',200000) 1 row created. SQL> / Enter value for model: 1098 Enter value for name: 'innova' Enter value for cost: 600000 Old 1: insert into cars values (&model,&name,&cost) New 1: insert into cars values (1098,'innova', 600000) insert into cars values(1098,'innova',600000) * ERROR at line 1: ORA-00001: unique constraint (SCOTT.SYS_C001266) violated CHECK CONSTRAINT: SQL> create table employ (rno number (5), name varchar(10),salary number(10) constraint no_ck check(salary between 10000 and 30000)); Table created. SQL> desc employ; NAME NULL? TYPE

--------------------------------------------------------------------------------RNO NAME SALARY NUMBER (5) VARCHAR2 (10) NUMBER (10)

SQL> insert into employ values (&rno,&name,&salary); Enter value for rno: 1 Enter value for name: 'sachin' Enter value for salary: 29000 Old 1: insert into employ values(&rno,&name,&salary) New 1: insert into employ values(1,'sachin',29000) 1 row created.

SQL> / Enter value for rno: 15 Enter value for name: 'dhoni' Enter value for salary: 40000 old 1: insert into employ values(&rno,&name,&salary) new 1: insert into employ values(15,'dhoni',40000) insert into employ values(15,'dhoni',40000) * ERROR at line 1: ORA-02290: check constraint (SCOTT.NO_CK) violated

FOREIGN KEY

SQL> create table admin (stuid number constraint stuid_pk primary key, name varchar(10),permit number(6)); Table created.

SQL> desc admin; NAME NULL? TYPE

----------------------------------------------------------------------------STUID NAME PERMIT NOT NULL NUMBER VARCHAR2 (10) NUMBER (6)

SQL> insert into admin values (&stuid,'&name',&permit); Enter value for stuid: 1 Enter value for name: ASWIN Enter value for permit: 80 Old 1: insert into admin values (&stuid,'&name',&permit) New 1: insert into admin values (1,'ASWIN',80) 1 row created.

SQL> / Enter value for stuid: 4 Enter value for name: SANJAY Enter value for permit: 45 Old 1: insert into admin values (&stuid,'&name',&permit) New 1: insert into admin values (4,'SANJAY',45) 1 row created.

SQL> select * from admin; STUID 1 4 NAME ASWIN SANJAY PERMIT 80 45

---------------------------------------------------

SQL> create table course (stuid number constraint sid_fk references admin (stuid), branch varchar(6),sec varchar(2)); Table created. SQL> insert into course values (&stuid,'&branch','&sec'); Enter value for stuid: 1 Enter value for branch: CSE Enter value for sec: A Old 1: insert into course values (&stuid,'&branch','&sec') New 1: insert into course values (1,'CSE','A') 1 row created. SQL> / Enter value for stuid: 4 Enter value for branch: IT Enter value for sec: A Old 1: insert into course values (&stuid,'&branch','&sec') New 1: insert into course values (4,'IT','A') 1 row created.

SQL> / Enter value for stuid: 6 Enter value for branch: CSE Enter value for sec: A Old 1: insert into course values (&stuid,'&branch','&sec') New 1: insert into course values (6,'CSE','A') insert into course values(6,'CSE','A') * ERROR at line 1: ORA-02291: integrity constraint (SCOTT.SID_FK) violated - parent key not found

SQL> delete from admin where stuid=5; 1 row deleted. SQL> delete from admin where stuid=1; Delete from admin where stuid=1 * ERROR at line 1: ORA-02292: integrity constraint (SCOTT.SID_FK) violated - child record found

SQL> select * from admin; STUID NAME PERMIT -----------------------------------------------------1 ASWIN 80 4 SANJAY 45

SQL> select * from course; STUID BRANCH SE ------------------------------1 CSE A 4 IT A

SQL> create table student (idno varchar(4),name varchar(10),dept varchar(4),degree varchar(6),year number(4)); Table created.

SQL> desc student; NAME NULL? TYPE ---------------------------------------------------------------------------------IDNO VARCHAR2 (4) NAME VARCHAR2 (10) DEPT VARCHAR2 (4) DEGREE VARCHAR2 (6) YEAR NUMBER (4) SQL> insert into student values ('&idno','&name','&dept','&degree',&year); Enter value for idno: A01 Enter value for name: AARON Enter value for dept: CSE Enter value for degree: BE Enter value for year: 2 Old 1: insert into student values ('&idno','&name','&dept','&degree',&year) New 1: insert into student values ('a01','aaron','cse','BE',2) 1 row created. SQL> / Enter value for idno: A02 Enter value for name: AKIL Enter value for dept: ECE Enter value for degree: BE Enter value for year: 2 Old 1: insert into student values ('&idno','&name','&dept','&degree',&year) New 1: insert into student values ('A02','AKIL','ECE','BE',2) 1 row created.

SQL> / Enter value for idno: A03 Enter value for name: BENNY Enter value for dept: IT Enter value for degree: B.TECH Enter value for year: 2 Old 1: insert into student values ('&idno','&name','&dept','&degree',&year) New 1: insert into student values ('A03','BENNY','IT','B.TECH',2) 1 row created. SQL> / Enter value for idno: B01 Enter value for name: COOK Enter value for dept: CSE Enter value for degree: BE Enter value for year: 1 Old 1: insert into student values ('&idno','&name','&dept','&degree',&year) New 1: insert into student values ('B01','COOK','CSE','BE',1) 1 row created. SQL> / Enter value for idno: B02 Enter value for name: DANNY Enter value for dept: MECH Enter value for degree: BE Enter value for year: 1 Old 1: insert into student values ('&idno','&name','&dept','&degree',&year) New 1: insert into student values ('B02','DANNY','MECH','BE',1) 1 row created. SQL> / Enter value for idno: B03 Enter value for name: ELAN Enter value for dept: IT Enter value for degree: B.TECH Enter value for year: 1 Old 1: insert into student values ('&idno','&name','&dept','&degree',&year) New 1: insert into student values ('B03','ELAN','IT','B.TECH',1) 1 row created.
5

SQL> SELECT * FROM STUDENT; IDNO NAME DEPT DEGREE YEAR

--------------------------------------------------------------------------------A01 A02 A03 B01 B02 B03 AARON AKIL BENNY COOK DANNY ELAN CSE ECE IT CSE MECH IT BE BE B.TECH BE BE B.TECH 2 2 2 1 1 1

6 rows selected. DISTINCT SQL> select distinct dept from student; DEPT ----------CSE ECE IT MECH SQL> select name from student; NAME ---------AARON AKIL BENNY COOK DANNY ELAN 6 rows selected. IN SQL> select * from student where year IN 2;

IDNO NAME DEPT DEGREE YEAR --------------------------------------------------------------------------------A01 AARON CSE BE 2 A02 AKIL ECE BE 2 A03 BENNY IT B.TECH 2 SQL> select * from student where name BETWEEN 'AARON' and 'COOK'; IDNO NAME DEPT DEGREE YEAR -------------------------------------------------------------------------------A01 AARON CSE BE 2 A02 AKIL ECE BE 2 A03 BENNY IT B.TECH 2 B01 COOK CSE BE 1 AS SQL> select IDNO as roll from student; ROLL ---------A01 A02 A03 B01 B02 B03 6 rows selected. SORT SQL> select * from student where year<3 order by name desc; IDNO NAME DEPT DEGREE YEAR

-----------------------------------------------------------------------------B03 B02 B01 A03 ELAN DANNY COOK BENNY IT MECH CSE IT B.TECH BE BE B.TECH 1 1 1 2

A02 A01

AKIL AARON

ECE CSE

BE BE

2 2

6 rows selected.

SQL> select * from student where year<3 order by dept asc; IDNO NAME DEPT DEGREE YEAR

------------------------------------------------------------------------------A01 B01 A02 A03 B03 B02 AARON COOK AKIL BENNY ELAN DANNY CSE CSE ECE IT IT MECH BE BE BE B.TECH B.TECH BE 2 1 2 2 1 1

6 rows selected. LIKE SQL> select * from student where name LIKE '%Y'; IDNO NAME A03 B02 BENNY DANNY DEPT DEGREE IT MECH B.TECH BE YEAR 2 1

-------------------------------------------------------------------------------

SQL> select * from student where name LIKE 'A%'; IDNO NAME A01 A02 AARON AKIL DEPT DEGREE CSE ECE BE BE YEAR 2 2

-----------------------------------------------------------------------------

IS NULL SQL> select * from student where IDNO IS NULL; no rows selected

LOGICAL OR SQL> select * from student where IDNO='A01' OR IDNO='B01'; IDNO NAME A01 B01 AARON COOK DEPT DEGREE CSE CSE BE BE YEAR 2 1

-------------------------------------------------------------------------------

RESULT: Thus DML commands were studied and executed in RDBMS

EX.NO: DATE: SUB QUERIES AND JOIN QUERIES INTRODUCTION: SUB QUERIES Nesting of queries, one within the other, is termed as a sub query.A statement containing a sub query is called.sunqueries are used to retrieve data from tables that depend on the values in the table itself. Example: SQL>select *from catalog where price>(select avg(price)from catalog);

NESTED SUB QUERIES: Having a subquery in the where or having clause of another sub query is called nested subqueries.

PARALLEL SUB QUERIES Parallel sub queries include more than one subquery into a query. EXERCISE: SQL> select * from employee where salary= (select max (salary) from employee); ROLLNO NAME SALARY -------------------------------------------------------------3 CLIFF 54334

SQL> select * from employee where salary=(select min(salary) from employee); ROLLNO NAME SALARY -----------------------------------------------------------1 AARON 23343

SQL> create table staff (ROLLNO number (6), DEPT varchar(5)); Table created. SQL> desc staff;

NAME ROLLNO DEPT

NULL?

TYPE NUMBER (6) VARCHAR2 (5)

-----------------------------------------------------------------------------

SQL> insert into staff values (&rollno,'&dept'); Enter value for rollno: 1 Enter value for dept: cse Old 1: insert into staff values (&rollno,'&dept') New 1: insert into staff values (1,'cse') 1 row created. SQL> / Enter value for rollno: 2 Enter value for dept: ece Old 1: insert into staff values (&rollno,'&dept') New 1: insert into staff values (2,'ece') 1 row created. SQL> / Enter value for rollno: 3 Enter value for dept: IT Old 1: insert into staff values (&rollno,'&dept') New 1: insert into staff values (3,'IT') 1 row created. SQL> / Enter value for rollno: 4 Enter value for dept: CSE Old 1: insert into staff values (&rollno,'&dept') New 1: insert into staff values (4,'CSE') 1 row created. SQL> / Enter value for rollno: 5 Enter value for dept: MECH Old 1: insert into staff values (&rollno,'&dept') New 1: insert into staff values (5,'MECH') 1 row created.

SQL> select * from staff; ROLLNO 1 2 3 4 5 JOIN QUERIES The purpose of a join is to combine the data spread across tables. SYNTAX: SELECT column FROM table1, table2 WHERE logical expression; There are basically three different types of join. They are Single join Self join Outer join Natural join SINGLE JOIN: It retrieves rows from two tables having a common column. It is further classified into equi-join and non equi-join. Equi join: A join which is based on equalities, is called an equai-join combines rows that have equivalent values for the specified columns. Non equi-join A non equi join specifies the relationship between column belonging to diff tables by making use of the relational operation (>, <, <=, >=, <>) other than =. NATURAL JOIN: The equijoin must produce a result containing two identical columns. If one of these columns is eliminated, then that join is called the natural join. DEPT ECE ECE IT CSE MECH

-----------------------------------

SQL> select name, dept from employee, staff where employee.rollno=staff.rollno; NAME ANTON DHARUN FELTON GEENA HARRY SELF JOIN In a self-join is joined to itself. It compares values with a column of a single table. SQL> select name, dept from employee, staff where employee.rollno=staff.rollno; NAME ANTON FELTON DEPT CSE CSE DEPT CSE EEE CSE MECH ECE

---------------------------------

---------------------------------

OUTER JOIN: When tables are joined rows, which contain matching values in the join predicates, are returned sometimes, matching and non matching rows returned for the tables that are being joined. The outer join can be Left outer Right outer Full outer LEFT OUTER JOIN retains non-matching rows from the left table in the result and place null values in the attributes that comes from the right table. RIGHT OUTER JOIN retains non-matching attributes from the right table and FULL OUTER JOIN of that retains non-matching attributes from both tables. SQL> select * from mark; IDNO MARK1 1 90 MARK2 98
5

--------------------------------------------------

2 4 3 6 5

89 89 45 89 67

97 78 56 98 56

SQL> select * from student; IDNO NAME ----------------------1 AA 2 3 4 5 BB CC DD EE

SQL>select *from mark innerjoin student on markidno=studentidno; IDNO MARK1 MARK2 ID NO NAME ---------------------------------------------------------------------------------1 2 3 4 5 90 89 45 89 67 98 97 56 78 56 1 2 3 4 5 AA BB CC DD EE

SQL>select * from fulljoin student on mark.idno=student.idno; IDNO MARK1 MARK2 ID NO NAME

-----------------------------------------------------------1 2 3 4 5 90 89 45 89 67 98 97 56 78 56 1 2 3 4 5 AA BB CC DD EE

SQL>select *from mark rightjoin student on markidno=student.idno; IDNO MARK1 MARK2 ID NO NAME

-------------------------------------------------------------------------------1 2 4 3 5 90 89 89 45 67 98 97 78 56 56 1 2 4 3 5 AA BB DD CC EE

SQL>select *from mark rightjoin student on markidno=student.idno; IDNO MARK1 MARK2 ID NO NAME

--------------------------------------------------------------------------------1 2 4 3 5 90 89 89 45 67 98 97 78 56 56 1 2 4 3 5 AA BB DD CC EE

RESULT: Thus the sub queries and join queries were studied and executed in PL/SQL.

EX.NO: DATE: VIEWS

A View is a virtual relation that does not necessarily exist in the database but can be produced upon request by a particular user, at the time of request. CREATING A VIEW: The format of the CREATE VIEW statement is, CREATE VIEW viewcolumn [(newcolumn [WITH[CASCADE/LOCAL]CHECK OPTION] name [,])] AS subselect

The subselect are known as the defining query. If WITH CHECK option is specified, SQL ensures that if a row fails to satisfy the where clause of the given query of the view, It is not added to the underlying base table of the view. REMOVING A VIEW: A view is removed from the database with the DROP VIEW statement. SYNTAX: DROP VIEW viewname [RESTRICT/CASCADE] If CASCADE is specified, DROP VIEW deletes all related dependent objects, all objects that reference the view. If RESTRICT is specified and there are any other objects that depend for their existence on the continued existence of the view being dropped, the command is rejected. The default setting is RESTRICT. A horizontal view restricts a users access to selected rows of one or more tables. A vertical view restricts a users access to selected columns of one or more tables. UPDATABLE VIEW: For a view to be updatable, the DBMS must be able to trace any row or column back to its row or column in the source table. EXERCISE SQL> create view studentview as select * from student; View created. SQL> select * from studentview;

IDNO NAME BRAN DEGREE ----------------------------------------------------------1 ASHOK CSE BE 2 BHAVANA CSE BE 3 CAVIN CSE BE 4 DANNY IT B.TECH UPDATE VIEW SQL> update studentview set degree='BE' where idno=4; 1 row updated. SQL> select * from student; IDNO NAME 1 2 3 4 SELECT SQL> select * from studentview; IDNO NAME 1 2 3 4 BRAN ASHOK BHAVANA CAVIN DANNY CSE CSE CSE IT DEGREE BE BE BE BE BRAN ASHOK BHAVANA CAVIN DANNY CSE CSE CSE IT DEGREE BE BE BE BE

----------------------------------------------------------

-----------------------------------------------------------

DROP SQL> drop table student; Table dropped. SQL> select * from studentview; Select * from studentview * ERROR at line 1: ORA-04063: view "SCOTT.STUDENTVIEW" has errors

RESULT Thus the views was studied and executed in RDBMS

EX.NO: DATE: HIGH LEVEL PROGRAMMING LANGUAGE EXTENSIONS (CONTROL STRUCTURE, PROCEDURES AND FUNCTIONS) Aim: To implement PL/SQL program using control structures, procedures and functions. (a) CONTROL STRUCTURES: Introduction: An interactive control statement is used when we want to repeat the execution of one or more statements for specified number of times. If-then: The simplest way of IF statement associates a condition with a sequence of statements enclosed by the keywords THEN and END IF as follows: Syntax: IF condition THEN < Sequence_of_statements> END IF; The sequence of statements is executed only if the condition is true. If the condition is false or null, then it does nothing. The control passes to the next statement. If-then-else: The second form of IF statement adds the keyword ELSE followed by alternative sequence of statements, as follows Syntax: IF condition THEN Sequence_of_statements1 ELSE Sequence_of_statements2 ENDIF;

The sequence of statements in the ELSE clause is executed only if the condition is false or null. Thus the ELSE clause ensures that a sequence of statements is executed. If-then-elseif: Sometimes you want to select from several mutually exclusive alternatives. The third form of IF statement uses ELSEIF to introduce additional as follows Syntax: IF conditional1 THEN Sequence_of_statements1 ELSEIF condition2 THEN Sequence_of_statements2 ELSE Sequence_of_statements3 ENDIF; Case statement: Like the IF statement, the CASE statement selects one of statements to execute. However, to select the sequence the case statement uses a selector rather than multiple Boolean expressions. The CASE statement has the following form Syntax: CASE selector WHEN expression1 THEN sequence_of_statements1; WHEN expression2 THEN sequence_of_statements2; WHEN expression THEN sequence_of_statementsN;

[ELSE sequence_of_statementsN+1;] END CASE; Loop:

The simplest form of loop statements is the basic loop which encloses a sequence of statements between the keyword LOOP and ENDLOOP as follows Syntax: LOOP Sequence_of_statements END LOOP; With each iteration of the loop, the sequence of the statements is executed then the control resumes at the top of the loop. If further processing is undesirable or impossibly you can use an EXIT statement to complete the loop. Exit: The EXIT statement forces a loop to complete unconditionally. When an EXIT statement is encountered the loop completes immediately and control passes to the next statement. Syntax: LOOP . IF condition THEN EXIT; END IF; END LOOP; While loop: The while loop statement associates a condition with a sequence of statements enclosed by the keywords LOOP and END LOOP as follows Syntax: WHILE condition LOOP Sequence_of_statements END LOOP; Before each iteration of the loop the condition is evaluated. If the condition is true the sequence of statements is executed then the control resumes at the loop. If the condition is false or null the loop is bypassed and the control passes to the next statement.

For loop: The number of iterations through FOR loop is known before the loop is entered. FOR loops iterate over a specified range of integers, the range is part of an iteration scheme, which is enclosed by the keywords FOR and LOOP. A double dot (..) serves as the range operator. Syntax: FOR counter IN [REVERSE] Loer_bound..higher_bound LOOP Sequence_of_statements END LOOP; GOTO statement: The GOTO statement branches to a label unconditionally. The label must be unique within its scope and must preceed an executable statement or a pl/sql block. When executed the GOTO statement transfers control to the labeled statement or block. Syntax: Begin GOTO insert_row; INSERT INTO values END;

NULL statement: The null statement does nothing other than pass control to the next statement. In a conditional construct the NULL statement tells readers that a possibility has been considered, but no action is necessary. (b) PROCEDURES: The procedure is a program that performs an action and does not return a value. A procedure has two parts: the specification and the body. The procedure spec begins with the keyword PROCEDURE and ends with the procedure name or a parameter list. Parameter declarations are optional. Procedures that take no parameters are written without parentheses.

The procedure body begins with the keyword IS (or AS) and ends with the keyword END followed by an optimal procedure name. The procedure body has three parts: a declarative part, an executable part, and an optional exception-handling part. The declarative part contains local declarations, which are placed between the keywords IS and BEGINS. The keyword DECLARES, which introduces declarations in an anonymous PL/SQL block, is not used. The executable part contains statements, which are placed between the keywords BEGIN, and EXCEPTION (or END). Syntax: CREATE [OR REPLACE] PROCEDURE procedure_name [(parameter, parameter)] IS [declaration_section] BEGIN Executable_section [EXCEPTION Exception_section] END[procedure_name]; (c) FUNCTIONS: The function is a program that might perform an action and does return a value. A function is a subprogram that computes a value. Like a procedure, a function has two parts: the spec and the body. The function spec begins with the keyword FUNCTION and ends with the RETURN clause, which specifies the data type of the return value. Parameter declaration is optional. Functions that take no parameters are written without parentheses. The function body begins with the keyword IS (or AS) and ends with keyword END followed by an optional function name. The function body has three parts: a declarative part, an executable part, and an optional exception-handling part. The declarative par contains local declarations, which are placed between the keywords IS and BEGIN. The keywords DECLARE is not used. The executable part contains statements, which are placed between the keywords BEGIN and EXCEPTION (or END). Syntax:
5

CREATE [OR REPLACE] FUNCTION function_name[(parameter[,parameter])] AS [declaration_section] BEGIN executable_section RETURN END [function_name];

EXERCISE: SQL> create or replace function f1 (id number) return character is 2 adr character (20); 3 begin 4 select addr into adr from employee where eid=id; 5 return adr; 6 end; 7/ Function created. SQL> declare 2 id number (4); 3 ad character (20); 4 begin 5 id: =&id; 6 ad: =f1 (id); 7 if ad='Bombay' then 8 update employee set addr='mumbai' where eid=id; 9 end if; 10 end; 11 / Enter value for id: 4444 Old 5: id: =&id; New 5: id: =4444;

PL/SQL procedure successfully completed. SQL> select * from employee where eid=4444; EID 4444 NAME SUNIL DOB 21-DEC-81 ADDRS MUMBAI DESIG DEPTNO M SALARY 13000 ---------------------------------------------------------------------------------------------------------------M CASHIER 2 M

SQL> create or replace procedure p2(id number) is 2 adr character (20); 3 begin 4 update employee set addr='goa' where eid=id; 5 end; 6/ Procedure created. SQL> select * from employee where eid=4444; EID 4444 NAME SUNIL DOB 21-DEC-81 ADDRS DELHI DESIG DEPTNO M SALARY 13000 ---------------------------------------------------------------------------------------------------------------M CASHIER 2 M

SQL> exec p2 (4444); PL/SQL procedure successfully completed. SQL> select * from employee where eid=4444; EID 4444 NAME SUNIL DOB 21-DEC-81 ADDRS GOA DESIG DEPTNO M SALARY 13000 ---------------------------------------------------------------------------------------------------------------M CASHIER 2 M

RESULT: Thus the procedures and functions were studied and executed in PL/SQL.

EX.NO: DATE: FRONT END TOOLS AIM: Basic Study of VB Front end Tools. Introduction: Visual basic uses object oriented techniques to create program that are powerful, robust and efficient. Start programs Microsoft visual studio Microsoft visual basic 6.0 Project: Each application in visual basic is called as project. A project is a collection of forms, modules, user controls and data reports etc. it organizes the forms and modules. The project is saved with the extension .vbp Forms: A form is a collection of controls. The controls are placed on the form. The form also has its own properties and methods. It has the extension .frm. an application. Visual basic is referred to as an integrated development environment (IDE). IDE consists of following elements, Title bar Menu bar Tool bar Tool box Control menu Project explorer window Properties window Object browser Form designer Code editor window - 43 -More than one form may be used in

Form layout window

TOOL BAR:

ADDING AND REMOVING TOOLBAR: Right click anywhere on the menu bar,or choose toolbars from the view menu.the Select the type of standard toolbar that you want from the pop-up menu. If a check is Under the menu, there is a toolbar. Toolbar is used to quick access the commonly used menu commands. There are few build in toolbars, Standard toolbar Edit toolbar Debug toolbar Form edit toolbar

toolbar pop-up menu appears. to the left of the toolbar type, that toolbar is already visible.

STANDARD TOOLBAR: The standard toolbar is the central toolbar in the visual basic IDE. The standard toolbar offers many features found in the file, project, debug and run menu. The standard toolbar enables fast access to often used functionally and information. THE EDIT TOOLBAR: The extended edit menu and some debug menu functions from yhe edit toolbar can be accessed. The features of edit toolbar are similar to those of the edit menu. You can cut,copy and paste text. You can manipulate the layout of the code and do text selection, searches and replacement. Also you can use automatic coding features such as quick info. THE DEBUG TOOLBAR: The debug toolbar enables you to access the debugging functions of the visual basic IDE. You can use the debug toolbar to test the program and restore errors that might occur. When you debug a program you do such things as run the code a line at a time. THE FORM EDITOR TOOLBAR: You can use the form editor toolbar to size, move, and align controls on a form. The form editor toolbar has the same set of features as the format menu. You align and size multiple controls on a form with the form editor toolbar. There are small download facing arrowheads to the right of the align, centre and make toolbar buttons. These arrowheads indicate that a dropdown menu will appear when you select that toolbar button. PROJECT EXPLORER WINDOW: To experiment with the project explorer window, click the toggle folders button. Notice that the folders are collapsed. To expand the folders, click the toggle button again. Still on the project explorer window, click view code. You are presented with the code editor window. To send the code editor window to the background again, on the project explorer windows, click the view object button. DEFAULT CONTROLS:

Common properties: Important common properties include the following, Name Index Left Top Height Width Enabled Visible

Controls contained in the visual basic toolbox:


1)

Picture box: Displays graphics. Can also serve as a container for other controls. Label box: Displays text that user cannot edit. Property: caption. Text box: Displays text. Allows the user to enter and edit text. Property: text. Frame: Serves as a container for other commands. Provides grouping of controls. Command buttons: Allows the user to initiate actions by clicking the button. Check box: Lets the user make a true/false choice. Option button: Lets the users choose from one option from a group of items. Property: caption. Combo box: Lets the users choose from a list of items or enter new values. Property: caption. List box: Lets the user choose from a list of items. Property: list. Horizontal / Vertical scroll box: Lets the user choose a scrollbar value based on the position Timer: Lets the program perform functions on timed basics. Drive list box: Let the user select a disk drive.

Property: caption, picture.


2)

3)

4)

Property: caption.
5) 6) 7)

8)

9)

10)

of button in the bar.


11) 12)

13) 14) 15) 16) 17)

Directory list: Let the users select a box directory or folders. File list box: Lets the user select a file. Shape: Displays a shape on the form. Line: Displays a line on the form. Image: similar to a picture box control, uses fewer system resources but doesnt support as Data control: Provides an interface between the program and a data source. OLE: Provides a connection between the program and an OLE server. Common dialog: Allows use of windows standard dialog boxes to retrieve information such

many properties, events and methods.


18) 19) 20)

as filenames and colors. Examples: Picture box: Private sub command1_click () Picture1.visible=true Picture2.visible=false End sub Private sub command2_click () Picture1.visible=false Picture2.visible=true End sub Label: Place a two label box controls in the form Private Sub Form_Load() Label1.Caption = "WIT" Label2.Caption = "TCPS" End Sub Private Sub Form_Click() Label1.Caption = "WORLD" Label2.Caption = "COMPUTER" End Sub Text box: There are three types of text box control

Single line textbox Password textbox Multi text box

Single line textbox: In this type of textbox, it will accept only one single line. Place three label boxes and three text boxes and place the code in the code window Private Sub Text3_GotFocus () text3.Text=Val (text1.Text) +Val (text2.Text) End Sub Multi line textbox: Text box access more than one line (more rows). You can change property, multiline as true. Password textbox: This object has two main properties, namely, Check box: Private Sub Check1_Click () If (Check1.Value = 1) Then Text1.FontBold = True Else Text1.FontBold = False End If End Sub Option button: Place a frame and 4 radio buttons in the form Private Sub Option1_Click () If (Option1.Value = True) Then Frame1.BackColor = vbBlue End If Password char. Max length

End Sub Private Sub Option2_Click () If (Option2.Value = True) Then Frame1.BackColor = vbGreen End If End Sub Private Sub Option3_Click () If (Option3.Value = True) Then Frame1.BackColor = vbYellow End If End Sub Private Sub Option4_Click () If (Option4.Value = True) Then Frame1.BackColor = vbRed End If End Sub Combo box: Private Sub Command1_Click () Text1.SetFocus Combo1.AddItem (Text1.Text) Text1.Text = " " End Sub Private Sub Command2_Click () Combo1.RemoveItem (Combo1.ListIndex) End Sub Private Sub Command3_Click () For i = 0 To (Combo1.ListCount - 1) Combo1.RemoveItem (0) next1
5

End Sub Private Sub Command4_Click () MsgBox (Combo1.ListCount) End Sub List box: Private Sub List1_DblClick () 'Add the item to the other list' List2.AddItem List1.Text 'Remove the item from this list' List1.RemoveItem List1.ListIndex End Sub Private Sub List2_DblClick () 'Add the item to the other list' List1.AddItem List2.Text 'Remove the item from this list' List2.RemoveItem List2.ListIndex End Sub Timer control: Timer control has only one event, called approximately as timer event. Timer occurs when a preset interval has elapsed. The timer control does not support ay methods. Private Sub Form_Click() Timer1.Enabled = False End Sub Private Sub Timer1_Timer () Label1.Caption = Time End Sub File list box: Program for drive list box, directory list and file list box.
5

Private Sub Drive1_Change () Dir1.Path = Drive1.Drive End Sub Private Sub File1_Click () picture1.Picture = Load (Dir1.Path + ("\") + File1.List (File1.ListIndex)) End Sub Private Sub Form_Load() Text1 = "*.bmp" End Sub Private Sub Text1_Change () File1.Pattern = Text1.Text End Sub Image controls: Program for image and timer control Private Sub Timer1_Timer () If (Image1.Left >= 10) Then Image1.Left = Image1.Left - 65 Else Image1.Left = 8000 End If If (image2.Left <= 8000) Then image2.Left = image2.Left + 59 Else image2.Left = 0 End If End Sub

Program for image and scrollbars: Design mode: Private Sub HScroll1_Change () Image1.Width = Image1.Width - HScroll1.Value HScroll1.Width = Image1.Width vscroll.Left = Image1.Left + Image1.Width End Sub Private Sub VScroll1_Change () Image1.Height = Image1.Height - vscroll.Value VScroll1.Height = Image1.Height HScroll1.Top = Image1.Top + Image1.Height End Sub

RESULT: Thus the above VB front-end tools are studied successfully.

EX.NO: DATE: FORMS AIM: To design and implement payroll processing system ALGORITHM: 1. Place all the controls in the form as shown. 2. To place the ADO control do the following procedure: Go to Project Components Select the check box showing Microsoft ADO data control. Press OK. 3. Place the ADO control on the form.
4. Create a table in SQL plus and insert some values in it. 5. Now type the command commit and return back to Visual Basic. 6. Select the ADO control and right click it to select the ADODC properties. 7. A dialog box will appear, press the build button. Select MICROSOFT OLEDB

provider for Oracle. Press next button.


8. In the connection tab, give the server name, user name and password. 9. Press the Test Connection button. A message box will appear if the steps were

followed correctly. Press OK button. 10. Select Authentication tab. Give the user name and password again. Select record source tab. In the table or stored procedure name combo box, select the table name. Give OK. 11. Now select the text buttons one by one and in their properties window, set the data source combo box to point to adodc1. Select the corresponding field of the text box in the data field combo box.
5

12. Write the coding for the command buttons and run the form.

Fig: the components dialog box adds the ado data control to a project

To open the property pages click the button with an ellipsis on it for the property labeled (custom) at the top of the properties listed in the properties window.

Fig: ADO data control has a graphical interface Ado data control also provides property open to the general page, which includes the data source name (DSN) . DSNs describe a data source that has been defined on a computer.

Fig: general page of the ADO data control property pages

Fig: Data Link properties

Fig: authentication page of the ADO data control property pages. LINKING CONTROLS TO THE ADO DATA CONTROL:

Fig: record source page of the ADO data control property pages.

Thus ADODB connection is made. CHANGES TO BE MADE IN THE TEXT:


click the textbox-> do the following changes in the properties SELECT the text-- clear it Select the datasource---in that select the datasource name then select the datafield------select the name of the respective field.

Then select the dataformat----.click--select general-apply----.ok

CHANGES TO BE MADE IN THE LABEL: Click the label--select the caption--.enter the respective name.

FORM DESIGN:

TABLE CREATION: SQL> create table proll(ename varchar2(20),eid varchar2(20), bsal number(20), lt number(5), da number(20), hra number(20),provfund number(20),ca number(29),lop number(10)); Table created. SQL> insert into proll values ('&ename','&eid', &bsal, &lt, &da, &hra, &pf, &ca, &lp); Enter value for ename: T.SANGEETHA Enter value for eid: 100 Enter value for bsal: 20000 Enter value for lt: 3 Enter value for da: 1200 Enter value for hra: 1600 Enter value for pf: 2000 Enter value for ca: 0 Enter value for lp: 0
5

Old 1: insert into proll values ('&ename','&eid', &bsal, &lt, &da, &hra, &pf, &ca, &lp) New 1: insert into proll values ('T.SANGEETHA','100', 20000, 3, 1200, 1600, 2000, 0, 0) 1 row created. SQL> / Enter value for ename: VIJAYA Enter value for eid: 101 Enter value for bsal: 15000 Enter value for lt: 6 Enter value for da: 1200 Enter value for hra: 1100 Enter value for pf: 1500 Enter value for ca: 0 Enter value for lp: 0 Old 1: insert into proll values ('&ename','&eid', &bsal, &lt, &da, &hra, &pf, &ca, &lp) New 1: insert into proll values ('VIJAYA','101', 15000, 6, 1200, 1100, 1500, 0, 0) 1 row created. SQL> COMMIT; Commit complete. SQL> SELECT * FROM PROLL; ENAME EID BSAL LT DA HRA

-------------------- ----- ---------- ---------- ---------- ---------PROVFUND CA LAP

---------- ---------- ---------T.SANGEETHA 2000 VIJAYA 1500 0 0 0 101 0 15000 6 1200 1100 100 20000 3 1200 1600

PROGRAM CODINGS

Private Sub Compute_Click () If Val (Text4.Text) <= 12 Then Text9.Text = Val (0) Text10.Text = (Val (Text3.Text) + Val (Text5.Text) + Val (Text6.Text) + Val (Text7.Text)) Val (Text8.Text) Else Text9.Text = (Val (Text4.Text) - Val (12)) * 100 Text10.Text = (Val (Text3.Text) + Val (Text5.Text) + Val (Text6.Text) + Val (Text7.Text)) (Val (Text8.Text) + Val (Text9.Text)) End If End Sub Private Sub Exit_Click () End End Sub Private Sub Addrecord_Click () Adodc1.Recordset.AddNew End Sub Private Sub Saverecord_Click() Adodc1.Recordset.Update End Sub Private Sub Deleterecord_Click() Adodc1.Recordset.Delete End Sub

OUTPUT:

RESULT: Thus, payroll processing system was designed and implemented successfully. .EX.NO:

DATE: HIGH LEVEL LANGUAGE EXTENSIONS WITH TRIGGERS AIM: To study and execute Triggers in RDBMS. Definition & Syntax: TRIGGER A database trigger is a stored procedure that is fired when an insert, update or delete statement is issued against the associated table. Database triggers can be used for the following purposes.

To generate data automatically. To enforce complex integrity constraints. (e.g. Checking with sysdate, checking with data in another table). To customize complex security authorizations. To maintain replicate tables. To audit data modifications.

Syntax for Creating Triggers The syntax for creating a trigger is given below CREATE OR REPLACE TRIGGER <trigger_name> [BEFORE/AFTER] [INSERT/UPDATE/DELETE] ON <table_name> [FOR EACH statement/FOR EACH row] [WHEN <condition>] PL/SQL block;

PARTS OF A TRIGGER A database trigger has three parts, namely, a trigger statement, a trigger body and a trigger restriction.

TRIGGER STATEMENT: A trigger statement specifies the DML statements like update, delete and insert and it fires the trigger body. It also specifies the table to which the trigger is associated.

TRIGGER BODY: Trigger body is a PL/SQL block that is executed when a triggering statement is issued.

TRIGGER RESTRICTION: Restrictions on a triggers can be achieved using the WHEN clause as shown in the syntax for creating triggers. They can be included in the definition of a row trigger, where in, the condition in the WHEN clause is evaluated for each row that is affected by the trigger.

TYPES OF TRIGGER: Triggers are categorized into the following types based on when they are fired: Before After For each row For each statement (default)

BEFORE /AFTER OPTIONS: The before/after options can be used to specify when the trigger body should be fired with respect to the triggering statement. If the user includes a BEFORE option, then, Oracle fires the trigger before executing the triggering statement. On the other hand, if AFTER is used, then, Oracle fires the trigger after executing the triggering statement.

FOR EACH ROW / STATEMENT: When the FOR EACH ROW / STATEMNT option included in the create trigger syntax specifies that the trigger fires once per row. By default, a database trigger fires for each statement. Using a combination of the above options, we can assign 12 types of triggers to a database table. Before update row / statement Before delete row / statement Before insert row / statement After update row / statement After delete row / statement After insert row / statement

EXERCISE: 1. Write a PL/SQL program to create a trigger before the user inserts the data into the table. 2. Write a PL/SQL program to create a trigger before the user delete the data from the table. 3. Write a PL/SQL program to create a trigger before the user changes the value of the salary of the employee. ANSWERS: SQL>create or replace trigger ins1 before insert on emp begin raise_application_error(-20001,'you cant insert a row'); end; OUTPUT: SQL>insert into emp values (&eid,'&name','&dob','&addr','&sex','&desig',&deptno,'&maritsta',&salary); SQL>insert into emp values (&eid,'&name','&dob','&addr','&sex','&desig',&deptno,'&maritsta',&salary);

ERROR at line 1: ORA-20001: you cant insert a row ORA-06512: at "CSE382.ins1", line 2 ORA-04088: error during execution of trigger 'CSE382.ins1' SQL>create or replace trigger del1 before delete on emp begin raise_application_error(-20001,'you cant delete a row'); End;

OUTPUT: SQL>delete from emp where eid=4444; Delete from emp where eid=4444; * ORA-20001: you cant delete a row ORA-06512: at "CSE382.DEL1", line 2 ORA-04088: error during execution of trigger 'CSE382.DEL1' SQL> create trigger upd1 before update on emp for each row 2 begin 3 if: new.sal < 1000 then 4 raise_application_error(-20001,'salary cant be low than this'); 5 end if; 6 end; 7/ Trigger created. SQL> update emp set sal=500 where dno=2; Update emp set sal=500 where dno=2 * ERROR at line 1: ORA-20001: salary cant be low than this ORA-06512: at "CSE382.UPD1", line 3 ORA-04088: error during execution of trigger 'CSE382.UPD1'

RESULT: Thus the usage of trigger were studied and executed in RDBMS.

EX.NO: DATE: MENUS INTRODUCTION: Menus are created using the menu editor, which is a dialog box. Submenus and separator bars are also created with the menu editor. It is used to establish and maintain the structure of menus. no other method is currently available for creating a menu in visual basic.

CREATING A MENU IN THE MENU EDITOR: To open the menu editor, open a form window. Then choose menu editor from the tools menu or press CTRL-E.

ADDING MENU BAR TITLES: 1. Open the menu editor.


2. Enter FILE into the caption text box, add an ampersand (&) before a letter makes

that letter the access key for the item.


3. Enter menu file into the name text box. Combining the prefix for the menu control

with the caption of a menu provides a consistent and easy to follow naming convention.
4. Click the next button. 5. Repeat step1 through4, replacing file with edit(&edit; menu edit),view(&view;

menu view), and so on.

ADDING MENU COMMANDS:


1. Open the form from the previous section in the form window 2. Open the menu editor. 3. Select the edit menu from the list box at the bottom of the dialog box.87 4. Click the insert button. This inserts a menu item before the one that is currently

selected. 5. click the right arrow button to make this item one level below the menu item above it ADDING SUB MENUS:
1. Open the form from the previous section in the form window.

2. Open the menu editor.


3. Select the open menu form from the list box at the bottom of the dialog box.

4. Click the insert button.


5. Click the right arrow button to make this item one level below the menu item above

it(two level from the menu titles) 6. Make the first item in the submenu text file and name it MnuFileNewTextFile.

ADDING SEPARTOR BARS:


1. Open the form from the previous section in the form window.

2. Open the menu editor.


3. Select the save menu form from the list box at the bottom of the dialog box.

4. .Click the insert button.


5. Enter a single dash (-) as the caption and name the menu menu File Sepator Bar1. 6. Select the exit menu from the list box at the bottom of the dialog box. 7. Click the insert button. 8. Enter a single dash (-) as the caption and name the menu mnuFileSeparatorBar2.

RESULT: Thus the above program was studied and executed successfully.

EX.NO:

DATE: REPORTS Aim: To generate reports by using VB and oracle Steps:


1. Project Components Designer tabCheck the following

Data Report Data Environment

2. Project Explorer Right click Add Data Environment. 3. Click connection1 propertiesMS OLEDB provider for oracleClick next type

the username and password in data link properties click test connection and it will display the message if the connection is true.
4. Right click the connectio1 in data environment add command option click command1

in connection1 Go to properties To enter database object table and select the object name.
5. Project Explorer Right click Add data report in data report properties. Set the

following properties

Data source Give data environment name. Data member Give command name.

6. Drag the command1 object in data report in detail section. 7. Arrange the title in page header section and design the data report in specified section.
8. Create one form with one command button name in show report.

Button click event Report name. Show Eg Data report1.Show

Result: Thus the above program was studied and executed successfully.

You might also like