0% found this document useful (0 votes)
206 views

Study of Basic SQL Commands

The document discusses various SQL commands like CREATE, INSERT, SELECT, ALTER, DROP etc. It provides examples of creating tables with and without primary keys, inserting values, selecting, updating, altering and dropping tables. The different types of SQL commands - DDL, DML, DCL are also explained. Examples demonstrate how to create primary keys using ALTER command, drop primary keys, and create foreign keys between tables.

Uploaded by

prsd912010
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
206 views

Study of Basic SQL Commands

The document discusses various SQL commands like CREATE, INSERT, SELECT, ALTER, DROP etc. It provides examples of creating tables with and without primary keys, inserting values, selecting, updating, altering and dropping tables. The different types of SQL commands - DDL, DML, DCL are also explained. Examples demonstrate how to create primary keys using ALTER command, drop primary keys, and create foreign keys between tables.

Uploaded by

prsd912010
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 73

 

 EX: NO: 1                   

STUDY OF BASIC SQL COMMANDS

AIM:

      To execute and verify the Basic SQL commands.

PROCEDURE:

      STEP 1: Start

      STEP 2: Create the table with its essential attributes.

      STEP 3: Insert attribute values into the table

      STEP 4: Execute different Commands and extract information from the table.

      STEP 5: Stop 

SQL COMMANDS

1. COMMAND NAME: CREATE

COMMAND DESCRIPTION: CREATE

  Command is used to create objects in database.

2. COMMAND NAME: INSERT

    COMMAND DESCRIPTION: INSERT

  Command is used to insert the values to the table.

3. COMMAND NAME: SELECT

    COMMAND DESCRIPTION: SELECT

      Command is used to display the table & table values.

4. COMMAND NAME: ALTER

    COMMAND DESCRIPTION: ALTER

  Command is used to alter the structure of database.


5. COMMAND NAME: DROP

     COMMAND DESCRIPTION: DROP

  Command is used to delete the object from database.

6. COMMAND NAME: TRUNCATE

    COMMAND DESCRIPTION: TRUNCATE

  Command is used to remove all the records in the table including the space allocated for the
table.

7. COMMAND NAME: COMMENT 

COMMAND DESCRIPTION:

      Command is used to add the comments to the table.

8. COMMAND NAME: RENAME

    COMMAND DESCRIPTION:

      Command is used to rename the objects.

9. COMMAND NAME: UPDATE

    COMMAND DESCRIPTION: UPDATE

  Command is used to update the values    

10. COMMAND NAME: DELETE

     COMMAND DESCRIPTION: DELETE

      Command is used to delete the constraint from the table    

11. COMMAND NAME: GRANT

      COMMAND DESCRIPTION: GRANT

      Command is used to give user’s access privilege to database.    

12. COMMAND NAME: REVOKE

      COMMAND DESCRIPTION: REVOKE

      Command is used to withdraw access privilege given with the grant.   


 

TYPES OF COMMANDS:

DDL (DATA DEFINITION LANGUAGE)

 1. CREATE

2. ALTER

3. DROP

4. TRUNCATE

5. COMMENT

6. RENAME 

DML (DATA MANIPULATION LANGUAGE)

SELECT

INSERT

UPDATE

DELETE 

DCL (DATA CONTROL LANGUAGE) 

GRANT

REVOKE

        

COMMANDS EXECUTION

CREATION OF TABLE WITHOUT PRIMARY KEY

SQL> create table employee (Employee_name varchar2 (10), employee_no number (8),
dept_name varchar2 (10), dept_no number (5), date_of_join date); 

Table created.

 TABLE DESCRIPTION
SQL> desc employee; 

Name                                    Null?                 Type 

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

EMPLOYEE_NAME                            VARCHAR2(10)

EMPLOYEE_NO                                  NUMBER(8) 

DEPT_NAME                                       VARCHAR2(10) 

DEPT_NO                                             NUMBER(5) 

DATE_OF_JOIN                                  DATE   

CREATION OF TABLE WITH PRIMARY KEY

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

SQL> create table employee1 (Employee_name varchar2 (10), employee_no number (8) primary
key, dept_name varchar2 (10), dept_no number (5),date_of_join date); 

Table created. 

TABLE DESCRIPTION

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

SQL> desc employee1; 

Name                                    Null?                   Type 

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

EMPLOYEE_NAME                            VARCHAR2 (10) 

EMPLOYEE_NO            NOT NULL NUMBER (8) 

DEPT_NAME                                       VARCHAR2 (10) 

DEPT_NO                                             NUMBER (5) 

DATE_OF_JOIN                                   DATE      

 
INSERTION OF TABLE VALUES

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

SQL> insert into employee1 values ('Vijay',345,'CSE',21,'21-jun-2006'); 

1 row created. 

SQL> insert into employee1 values ('Raj',98,'IT',22,'30-sep-2006'); 

1 row created. 

SQL> insert into employee1 values ('Giri',100,'CSE',67,'14-nov-1981'); 

1 row created. 

SQL> insert into employee1 (Employee_name, employee_no, dept_name, dept_no,


date_of_join) values ('Vishva', 128, ‘ECE’, 87,'25-dec-2006'); 

1 row created. 

SQL> insert into employee1 values ('Ravi', 124,'ECE', 89,'15-jun-2005');

1 row created. 

SELECTION OR DISPLAY OF TABLE

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

SQL> select * from employee1; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME    DEPT_NO DATE_OF_J

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

Vijay                   345                      CSE               21                 21-JUN-06

Raj                       98                          IT                22                30-SEP-06

Giri                      00                       CSE               67                14-NOV-81

Vishva                 128                     ECE               87                25-DEC-06

Ravi                     124                     ECE               89                15-JUN-05 

UPDATE OF TABLE VALUES

----------------------------------------- 
SQL> update employee1 set employee_no=300 where dept_no=67; 

1 row updated.    

SQL> select * from employee1; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME    DEPT_NO DATE_OF_J

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

Vijay                           345                      CSE               21                 21-JUN-06

Raj                                98                          IT                22                30-SEP-06

Giri                             300                       CSE               67                14-NOV-81

Vishva                        128                       ECE               87                25-DEC-06

Ravi                            124                      ECE                89                15-JUN-05 

USING ALTER COMMANDS 

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

SQL> select * from employee; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME    DEPT_NO DATE_OF_J

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

Karthik                        98                       ECE                          35      14-FEB-05

Vijay                         100                        CSE                         98       15-AUG-01

praveen                     128                        ECE                         76       02-OCT-03 

SQL>  select * from employee1; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME    DEPT_NO DATE_OF_J

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

Raj                          98                              IT                22                 30-SEP-06

Giri                       100                           CSE               67                 14-NOV-81

Vishva                  128                           ECE               87                  25-DEC-06 

DROPPING PRIMARY KEY USING ALTER COMMAND 


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

SQL> alter table employee1 drop primary key; 

Table altered. 

SQL> desc employee1; 

Name                                  Null?                    Type 

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

EMPLOYEE_NAME                              VARCHAR2(10) 

EMPLOYEE_NO                                    NUMBER(8) 

DEPT_NAME                                         VARCHAR2(10) 

DEPT_NO                                               NUMBER(5) 

DATE_OF_JOIN                                    DATE     

CREATING PRIMARY KEY USING ALTER COMMAND 

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

SQL> alter table employee1 add primary key (employee_no); 

Table altered. 

SQL> desc employee1; 

Name                                         Null?                                 Type

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

EMPLOYEE_NAME                                         VARCHAR2(10) 

EMPLOYEE_NO                    NOT NULL       NUMBER(8) 

DEPT_NAME                                                    VARCHAR2(10) 

DEPT_NO                                                          NUMBER(5) 

DATE_OF_JOIN                                                DATE 

SQL> alter table employee add primary key (employee_no); 

Table altered.
SQL> desc employee; 

Name                                          Null?                                  Type 

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

EMPLOYEE_NAME                                                 VARCHAR2(10) 

EMPLOYEE_NO                  NOT NULL                 NUMBER(8) 

DEPT_NAME                                                            VARCHAR2(10) 

DEPT_NO                                                                  NUMBER(5) 

DATE_OF_JOIN                                                       DATE 

CREATING FORIEGN KEY USING ALTER COMMAND 

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

Note: For creation of foreign key, both the table should possess primary key with same             
attributes. Similarly for dropping employee 1 as well as employee table ,first the            
relationship i.e., primary key has to be removed from both the tables. 

SQL> alter table employee1 add foreign key (employee_no) references employee
(employee_no); Table altered.        

SQL> desc employee1; 

Name                                           Null?                         Type 

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

EMPLOYEE_NAME                                            VARCHAR2(10) 

EMPLOYEE_NO                     NOT NULL         NUMBER(8) 

DEPT_NAME                                                       VARCHAR2(10) 

DEPT_NO                                                             NUMBER(5) 

DATE_OF_JOIN                                                  DATE 

ADDING & MODIFYING CONSTRAINTS USING ALTER COMMAND 

------------------------------------------------------------------------------------------- 
SQL> select * from employee1; 

EMPLOYEE_N   EMPLOYEE_NO DEPT_NAME    DEPT_NO DATE_OF_J

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

Raj                              98                             IT                 22                  30-SEP-06

Giri                           100                          CSE                 67                  14-NOV-81

Vishva                      128                          ECE                 87                  25-DEC-06 

ADDING CONSTRAINTS TO TABLE 

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

SQL> alter table employee1 add (salary number); 

Table altered.  SQL> select * from employee1; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME   DEPT_NO DATE_OF_J   SALARY

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

Raj                            98                            IT                22               30-SEP-06

Giri                        100                          CSE               67                14-NOV-81

Vishva                    128                         ECE               87                25-DEC-06 

SQL> update employee1 set salary = 100 where employee_no=98; 

1 row updated. 

SQL> update employee1 set salary = 90 where employee_no=100; 

1 row updated. 

SQL> update employee1 set salary = 134 where employee_no=128; 

1 row updated.   

SQL> select * from employee1; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME DEPT_NO DATE_OF_J    SALARY

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

Raj                               98                       IT                   22               30-SEP-06       100


Giri                           100                    CSE                   67               14-NOV-81        90

Vishva                       128                   ECE                   87               25-DEC-06       134


MODIFYING THE CHARACTERISTIC OF CONSTRAINTS IN A TABLE 

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

Note: Before modifying the character of a column,first set the column values to null.The              
feature of a column can be altered only if all its values become null or empty. 

SQL> update employee1 set salary = ''where employee_no=100; 

1 row updated. 

SQL> update employee1 set salary = ''where employee_no=128; 

1 row updated.

SQL> update employee1 set salary =''where employee_no=98; 

1 row updated. 

SQL> select * from employee1; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME  DEPT_NO DATE_OF_J    SALARY

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

Raj                               98                          IT                22             30-SEP-06

Giri                            100                       CSE               67             14-NOV-81

Vishva                       128                       ECE               87             25-DEC-06 

Modifying the column of employee1 table 

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

SQL> alter table employee1 modify (salary varchar2 (10)); 

Table altered.      

SQL> select * from employee1; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME DEPT_NO DATE_OF_J    SALARY

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


Raj                                 98                          IT                22             30-SEP-06

Giri                              100                       CSE               67              14-NOV-81

Vishva                         128                       ECE               87              25-DEC-06  

SQL> update employee1 set salary ='90'where employee_no=100; 

1 row updated. 

SQL> update employee1 set salary ='134' where employee_no=128;

1 row updated. 

SQL> update employee1 set salary ='100'where employee_no=98; 

1 row updated. 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME    DEPT_NO DATE_OF_J SALARY

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

Raj                               98                           IT                22           30-SEP-06          100

Giri                            100                        CSE               67           14-NOV-81         90

Vishva                       128                        ECE               87            25-DEC-06         134 

Note: Differences (salary varchar2(10)) & ( salary number)   (Salary varchar2(10)) 

SALARY

----------- 100 90 134  ( salary number)   

SALARY

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

100  90 134    

ASSIGNING COMMENTS FOR TABLE

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

SQL> comment on table employee1 is 'EMPLOYEE DETAILS'; 

Comment created. 

SQL> select comments from user_tab_comments; 


COMMENTS

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

EMPLOYEE DETAILS   ASSIGNING COMMENTS FOR COLUMN 

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

SQL> comment on column employee1.EMPLOYEE_NO is 'EMPLOYEE REGISTRATION


NUMBER'; 

Comment created. 

SQL> select comments from USER_COL_COMMENTS;

COMMENTS --------------------------------------------------------- 

EMPLOYEE REGISTRATION NUMBER 

3 rows selected.   

DELETION OF TABLE VALUES 

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

SQL> select * from employee1; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME    DEPT_NO DATE_OF_J

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

Vijay                           345                       CSE                    21           21-JUN-06

Raj                                 98                         IT                     22           30-SEP-06

Giri                              100                      CSE                    67            14-NOV-81

Vishva                         128                      ECE                    87            25-DEC-06

Ravi                            124                       ECE                   89             15-JUN-05     

SQL> delete from employee1 where employee_no >344; 

1 row deleted. 

SQL> select * from employee1; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME    DEPT_NO DATE_OF_J


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

Raj                               98                           IT                22               30-SEP-06

Giri                           100                         CSE               67                14-NOV-81

Vishva                      128                         ECE               87                25-DEC-06

Ravi                          124                         ECE               89               15-JUN-05 

SQL>  delete from employee1 where employee_no =124; 

1 row deleted. 

SQL> select * from employee1; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME    DEPT_NO DATE_OF_J

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

Raj                              98                            IT                    22              30-SEP-06

Giri                           100                         CSE                    67              14-NOV-81

Vishva                      128                         ECE                    87               25-DEC-06 

GRANT COMMAND

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

SQL> grant insert,select,update,delete on employee1 to system; 

Grant succeeded. 

REVOKE COMMAND

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

SQL> revoke select,insert on employee1 from system; 

Revoke succeeded. 

RENAMING TABLE 

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

SQL> Rename employee1 to emp;

Table renamed.     
TRUNCATION OF TABLE

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

SQL> truncate table emp; 

Table truncated. 

SQL> select * from emp; 

no rows selected 

DROPPING OF TABLE 

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

SQL> drop table emp; 

Table dropped. 

                           

RESULT:  
 

      Thus the Special SQL commands has been verified and executed successfully.   

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EX: NO: 2                  

STUDY OF SPECIAL SQL COMMANDS

 AIM:

      To execute and verify the Special SQL commands.

PROCEDURE:

      STEP 1: Start 

      STEP 2: Create the table with its essential attributes.

      STEP 3: Insert attribute values into the table


      STEP 4: Execute different Commands and extract information from the table.

      STEP 5: Stop 

SQL COMMANDS

1. COMMAND NAME: COMMIT

     COMMAND DESCRIPTION: COMMIT

        Command is used to save the work done.

2. COMMAND NAME: SAVE POINT

    COMMAND DESCRIPTION: SAVE POINT

        Command is used to identify a point in a transaction in which it can be restored using Roll
back command.

3. COMMAND NAME: ROLLBACK

    COMMAND DESCRIPTION: ROLLBACK

      Command is used to restore database to original since last commit.

4. COMMAND NAME: MAX

    COMMAND DESCRIPTION: MAX

        Command is used to find the maximum among the entities in a particular attribute.   

5. COMMAND NAME: MIN

     COMMAND DESCRIPTION: MIN

        Command is used to find the maximum among the entities in a particular attribute.

6. COMMAND NAME: COUNT

    COMMAND DESCRIPTION: COUNT

      Command is used to count the entire entities in a particular attribute.

7. COMMAND NAME: SUM

    COMMAND DESCRIPTION: SUM

        Command is used to add all the entities with in the attribute.
8. COMMAND NAME: UNION

    COMMAND DESCRIPTION: UNION

        Command is used to compile all distinct rows and display all entities in both rows.

9. COMMAND NAME: UNIONALL

    COMMAND DESCRIPTION: UNIONALL

        Command is used to return all entities in both rows.       

10. COMMAND NAME: INTERSECT

     COMMAND DESCRIPTION: INTERSECT

        Command is used to display only similar entities in both rows.      

 11. COMMAND NAME: MINUS

      COMMAND DESCRIPTION: MINUS

  Command is used to display only the rows that don’t match in both queries.             
12.COMMAND NAME: AVG

       COMMAND DESCRIPTION: AVG

      Command is used to find average of entity in particular attribute.   

 TYPES OF COMMANDS

TCL(TRANSACTION CONTROL COMMANDS)

COMMIT

SAVEPOINT

ROLLBACK

SET OPERATORS

UNION

UNIONALL
INTERSECT

MINUS

ARITHMETIC OPERATORS

MAX

MIN

COUNT

AVG

SUM

 COMMANDS EXECUTION

CREATION OF TABLE

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

SQL> create table employee (Employee_Name varchar2 (10),Employee_no number primary


key, Dept_no number,Dept_name varchar2(10)); 

Table created. 

SQL>  create table employee1 ( Employee_Name varchar2(10),Employee_no number primary


key,Dept_no number,dept_name varchar2(10)); 

Table created. 

DESCRIPTION OF TABLE

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

SQL> desc employee1;             

Name                                    Null?                    Type

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

EMPLOYEE_NAME                                      VARCHAR2(10) 

EMPLOYEE_NO                NOT NULL        NUMBER 

DEPT_NO                                                       NUMBER 
DEPT_NAME                                                 VARCHAR2(10) 

SQL> desc employee;             

Name                                 Null?                         Type 

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

EMPLOYEE_NAME                                              VARCHAR2(10) 

EMPLOYEE_NO                     NOT NULL           NUMBER 

DEPT_NO                                                               NUMBER 

DEPT_NAME                                                         VARCHAR2(10) 

SELECTION OF TABLE VALUES

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

SQL> select * from employee; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                        45                        CSE

Vijay                                    877                        85                        EEE

Vignesh                                990                        95                        BME    

19

SQL> select * from employee1; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                        45                        CSE

Vishnu                                  476                       55                         IT

Vikram                                 985                       75                         ECE 


COMMIT & ROLLBACK COMMAND

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

SQL> select * from employee; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                        45                        CSE

Vijay                                    877                        85                        EEE

Vignesh                                990                        95                       BME 

SQL> commit;

Commit complete. 

SQL> delete from employee where employee_no=990;

1 row deleted.  SQL> select * from employee; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                        45                        CSE

Vijay                                    877                        85                        EEE 

SQL> rollback;

Rollback complete. 

SQL> select * from employee; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO      DEPT_NAME

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

Ganesh                                 234                        45                        CSE

Vijay                                    877                        85                        EEE

Vignesh                                990                        95                        BME       

SAVEPOINT & ROLLBACK COMMAND


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

SQL> select * from employee; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                        45                        CSE

Vijay                                    877                        85                        EEE

Vignesh                                990                        95                        BME  

SQL> savepoint vijay;

Savepoint created. 

SQL> update employee set dept_no=75 where employee_no=234;

1 row updated. 

SQL> delete from employee where employee_no=990;

1 row deleted. 

SQL> select * from employee; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                        75                        CSE

Vijay                                    877                        85                        EEE 

SQL> roll back vijay

Rollback complete.

SQL> select * from employee; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                        45                        CSE

Vijay                                    877                        85                        EEE


Vignesh                                990                        95                        BME 

ARITHMETIC OPERATORS

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

SQL> select * from employee; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                        45                        CSE

Vijay                                    877                        85                        EEE

Vignesh                                990                        95                        BME   

SQL> select sum (employee_no) from employee; 

SUM (EMPLOYEE_NO)

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

2101 

SQL> select avg (employee_no) from employee; 

AVG (EMPLOYEE_NO)

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

700.33333 

SQL> select max (employee_no) from employee; 

MAX (EMPLOYEE_NO)

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

990 

SQL> select min (employee_no) from employee; 

MIN (EMPLOYEE_NO)

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

234 
SQL> select count (employee_no) from employee; 

COUNT (EMPLOYEE_NO)

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

SET OPERATORS

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

SQL> select * from employee;

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                        45                        CSE

Vijay                                    877                        85                        EEE

Vignesh                                990                        95                        BME        

SQL> select * from employee1; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                        45                        CSE

Vishnu                                  476                       55                         IT

Vikram                                 985                       75                         ECE  

SQL> SQL> select employee_no from employee union select employee_no from employee1;
EMPLOYEE_NO

-----------        

234         476         877         985         990

SQL> select employee_no from employee union all select employee_no from employee1;
EMPLOYEE_NO

-----------        

234         877         990         234         476         985 


6 rows selected.                

  SQL> select employee_no from employee intersect select employee_no from employee1;
EMPLOYEE_NO

-----------        

234   

SQL> select employee_no from employee minus select employee_no from employee1;
EMPLOYEE_NO

-----------        

877        

990                              

RESULT:

        

      Thus the Special SQL commands has been verified and executed successfully.   
 
 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  

EX: NO: 3             

SQL COMMANDS FOR NESTED QUERIES AND JOIN QUERIES

  AIM:

      To execute and verify the SQL commands using nested queries and Join queries.

PROCEDURE:

      STEP 1: Start 

      STEP 2: Create the table with its essential attributes.

      STEP 3: Insert attribute values into the table

      STEP 4: Execute different Commands and extract information from the table.
      STEP 5: Stop 

 SQL COMMANDS

1. COMMAND NAME: INNER JOIN

     COMMAND DESCRIPTION: INNER JOIN

        Command returns the matching rows from the tables that are being joined.

2. COMMAND NAME: LEFT OUTER JOIN

    COMMAND DESCRIPTION: LEFT OUTER JOIN

      Command returns matching rows from the tables being joined and also non-matching row
from the left table in the result and places null values in the attributes that come from the right
side table.

3. COMMAND NAME: RIGHT OUTER JOIN

    COMMAND DESCRIPTION: RIGHT OUTER JOIN

      Command returns matching rows from the tables being joined and also non-matching row
from the right table in the result and places null values in the attributes that come from the left
side table.

4. COMMAND NAME: NESTED QUERY

    COMMAND DESCRIPTION: NESTED QUERY

        Command have query within another query.     

COMMANDS EXECUTION

 CREATION OF TABLE

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

SQL> create table employee (Employee_Name varchar2 (10), Employee_no number primary
key, Dept_no number, Dept_name varchar2 (10)); 

Table created. 

SQL> create table employee1 (Employee_Name varchar2 (10), Employee_no number primary
key, Dept_no number, dept_name varchar2 (10));
Table created. 

DESCRIPTION OF TABLE 

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

SQL> desc employee;            

Name                                 Null?                         Type 

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

EMPLOYEE_NAME                                              VARCHAR2(10) 

EMPLOYEE_NO                     NOT NULL           NUMBER 

DEPT_NO                                                               NUMBER 

DEPT_NAME                                                         VARCHAR2(10) 

SELECTION OF TABLE VALUES

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

SQL> select * from employee; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                        45                        CSE

Vijay                                    877                        85                        EEE 

Vignesh                                990                        95                        BME   

SQL> select * from employee1; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                        45                        CSE

Vishnu                                  476                       55                         IT

Vikram                                 985                       75                         ECE  

JOIN COMMANDS
------------------------- 

Note: Without defining foreign key, Join commands cannot be executed.

SQL> alter table employee1 add foreign key (employee_no) references


employee1( employee_no);  Table altered. 

INNER JOIN

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

SQL> select e.employee_name,d.dept_no from employee e,employee1 d where


e.employee_no=d.employee_no; 

EMPLOYEE_N   DEPT_NO

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

Ganesh                      45 

LEFT OUTER JOIN

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

SQL> select e.dept_name,d.dept_no from employee e,employee1 d where e.employee_no (+) = 


d.employee_no; 

DEPT_NAME    DEPT_NO

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

    CSE                       45 

RIGHT OUTER JOIN 

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

SQL> select e.dept_name,d.dept_no from employee e,employee1 d where e.employee_no =


d.employee_no (+);  

DEPT_NAME    DEPT_NO

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

CSE                            45 EEE   BME  

SUB-QUERY

-----------------
SQL> update employee set dept_no= (select sum (employee_no) from employee) where
employee_no=234; 

1 row updated. 

SQL> select * from employee; 

EMPLOYEE_N      EMPLOYEE_NO     DEPT_NO       DEPT_NAME

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

Ganesh                                 234                    2101                        CSE

Vijay                                    877                        85                        EEE

Vignesh                                990                        95                        BME 

SQL> create table sailor(sid number(4),sname char(15),rating number(4),age number(2),primary


key(sid));  Table created. 

SQL> desc sailor; 

Name                                      Null?      Type 

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

SID                                       NOT NULL  NUMBER(4) 

SNAME                                                CHAR(15) 

RATING                                              NUMBER(4) 

AGE                                                 NUMBER(2) 

SQL> insert into sailor values(&sid,'&sname',&rating,&age);

Enter value for sid: 11

Enter value for sname: john

Enter value for rating: 8

Enter value for age: 21

old   1: insert into sailor values(&sid,'&sname',&rating,&age) 

new   1: insert into sailor values(11,'john',8,21) 

1 row created. 
SQL> /

Enter value for sid: 12

Enter value for sname: lubber

Enter value for rating: 9

Enter value for age: 21

old   1: insert into sailor values(&sid,'&sname',&rating,&age)

new   1: insert into sailor values(12,'lubber',9,21) 

1 row created. 

SQL> /

Enter value for sid: 13

Enter value for sname: david

Enter value for rating: 7

Enter value for age: 22

old   1: insert into sailor values(&sid,'&sname',&rating,&age)

new   1: insert into sailor values(13,'david',7,22) 

1 row created. 

SQL> select * from sailor;        

SID SNAME               RATING        AGE

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

11  john                      8         21        

12  lubber                  9         21       

13  david                    7         22  

SQL> create table boat(bid number(4),bname char(15),color char(6),primary


key(bid),check(color in('red','blue','green'))); 

Table created.
SQL> desc boat; 

Name                                      Null?    Type 

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

BID                                       NOT NULL NUMBER(4) 

BNAME                                               CHAR(15) 

COLOR                                               CHAR(6) 

SQL> insert into boat values(&bid,'&bname','&color');

Enter value for bid: 102 

Enter value for bname: a2

Enter value for color: red

old   1: insert into boat values(&bid,'&bname','&color')

new   1: insert into boat values(102,'a2','red') 

1 row created. 

SQL> /

Enter value for bid: 101

Enter value for bname: a2

Enter value for color: blue

old   1: insert into boat values(&bid,'&bname','&color')

new   1: insert into boat values(101,'a2','blue') 

1 row created. 

SQL> /

Enter value for bid: 103

Enter value for bname: a3

Enter value for color: green

old   1: insert into boat values(&bid,'&bname','&color')


new   1: insert into boat values(103,'a3','green')  1 row created. 

SQL> select * from boat;        

BID BNAME           COLOR

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

102  a2               red       

101  a2              blue       

103  a3              green 

SQL> create table reserve(sid number(4),bid number(4),day date,primary key(sid,bid),foreign


key(references sailor,foreign key(bid)references boat); 

Table created. 

SQL> desc reserve; 

Name                                      Null?      Type

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

SID                                       NOT NULL  NUMBER (4) 

BID                                      NOT NULL  NUMBER (4)

DAY                                                  DATE 

SQL> insert into reserve values (&sid,&bid,'&day'); 

Enter value for sid: 11

Enter value for bid: 101

Enter value for day: 11-aug-09

old   1: insert into reserve values(&sid,&bid,'&day')

new   1: insert into reserve values(11,101,'11-aug-09') 

1 row created. 

SQL> /

Enter value for sid: 12


Enter value for bid: 102

Enter value for day: 15-sep-09

old   1: insert into reserve values(&sid,&bid,'&day')

new   1: insert into reserve values(12,102,'15-sep-09') 

1 row created. 

SQL> select * from reserve;        

SID        BID DAY

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

11        101 11-AUG-09       

12        102 15-SEP-09 

SQL> desc boat; 

Name                                           Null?     Type

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

BID                                       NOT NULL  NUMBER(4) 

BNAME                                                CHAR(15) 

COLOR                                                CHAR(6) 

SQL> insert into boat values(&bid,'&bname','&color');

Enter value for bid: 102

Enter value for bname: a2

Enter value for color: red

old   1: insert into boat values(&bid,'&bname','&color')

new   1: insert into boat values(102,'a2','red') 

1 row created. 

SQL> /

Enter value for bid: 101


Enter value for bname: a2

Enter value for color: blue

old   1: insert into boat values(&bid,'&bname','&color')

new   1: insert into boat values(101,'a2','blue') 

1 row created. 

SQL> /

Enter value for bid: 103

Enter value for bname: a3

Enter value for color: green

old   1: insert into boat values(&bid,'&bname','&color')

new   1: insert into boat values(103,'a3','green') 

1 row created. 

SQL> select * from boat;        

BID  BNAME        COLOR

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

102  a2               red       

101  a2               blue       

103  a3               green

SQL> create table reserve(sid number(4),bid number(4),day date,primary key(sid,bid),foreign


key(sid)references sailor,foreign key(bid)references boat); 

Table created. 

SQL> desc reserve; 

Name                                      Null?      Type

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

SID                                     NOT NULL  NUMBER (4) 


BID                                       NOT NULL  NUMBER (4) 

DAY                                                  DATE 

SQL> insert into reserve values(&sid,&bid,'&day');

Enter value for sid: 11

Enter value for bid: 101

Enter value for day: 11-aug-09

old   1: insert into reserve values(&sid,&bid,'&day')

new   1: insert into reserve values(11,101,'11-aug-09') 

1 row created. 

SQL> /

Enter value for sid: 12

Enter value for bid: 102

Enter value for day: 15-sep-09

old   1: insert into reserve values(&sid,&bid,'&day') 

new   1: insert into reserve values(12,102,'15-sep-09') 

1 row created.

SQL> select * from reserve;     

   SID        BID   DAY

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

11        101   11-AUG-09        

 12         102   15-SEP-09 

SQL> select sname from sailor where sid in(select sid from reserve where bid=103); 

no rows selected 

SQL> select sname from sailor where sid in(select sid from reserve where bid=102); 

SNAME
---------------

lubber 

SQL> select sid from reserve where bid in(select bid from boat where color='red');       

SID

----------       

12   

SQL> select color from boat where bid in(select bid from reserve where sid in(select sid from
sailore where sname='lubber')); 

COLOR

------

red         
 
 
 
 
 
 
 
 

RESULT:

       

      Thus the SQL commands for Joins and Nested queries has been verified and executed
successfully. 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EX: NO: 4                            

SQL COMMANDS FOR VIEWS

  AIM:
      To execute and verify the SQL commands for Views.

PROCEDURE:

      STEP 1: Start 

      STEP 2: Create the table with its essential attributes.

      STEP 3: Insert attribute values into the table.

      STEP 4: Create the view from the above created table.

      STEP 5: Execute different Commands and extract information from the View.

      STEP 6: Stop 

 SQL COMMANDS

1. COMMAND NAME: CREATE VIEW

     COMMAND DESCRIPTION: CREATE VIEW

        Command is used to define a view.

2. COMMAND NAME: INSERT IN VIEW

     COMMAND DESCRIPTION: INSERT

  Command is used to insert a new row into the view.

3. COMMAND NAME: DELETE IN VIEW

    COMMAND DESCRIPTION: DELETE

  Command is used to delete a row from the view. 

4. COMMAND NAME: UPDATE OF VIEW

    COMMAND DESCRIPTION: UPDATE

      Command is used to change a value in a tuple without changing all values in the tuple. 

5. COMMAND NAME: DROP OF VIEW 

    COMMAND DESCRIPTION: DROP

      Command is used to drop the view table                                                      

COMMANDS EXECUTION
 

CREATION OF TABLE

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

SQL> create table employee (Employee_name varchar2 (10),employee_nonumber(8),


dept_name varchar2(10),dept_no number (5),date_of_join date); 

Table created. 

TABLE DESCRIPTION

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

SQL> desc employee;

Name                                    Null?                 Type

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

EMPLOYEE_NAME                            VARCHAR2(10) 

EMPLOYEE_NO                                  NUMBER(8) 

DEPT_NAME                                       VARCHAR2(10) 

DEPT_NO                                             NUMBER(5)

DATE_OF_JOIN                                  DATE 

CREATION OF VIEW

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

SQL> create view empview as select


employee_name,employee_no,dept_name,dept_no,date_of_join from employee; 

View created. 

DESCRIPTION OF VIEW

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

SQL> desc empview; 

Name                                      Null?    Type 


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

EMPLOYEE_NAME                          VARCHAR2(10) 

EMPLOYEE_NO                                 NUMBER(8) 

DEPT_NAME                                      VARCHAR2(10) 

DEPT_NO                                            NUMBER(5)     

  SQL> select * from empview; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME     DEPT_NO

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

Ravi               124 ECE                89

Vijay              345 CSE                21

Raj                 98 IT                 22

Giri               100 CSE                67 

MODIFICATION 

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

SQL> insert into empview values ('Sri',120,'CSE',67,'16-nov-1981'); 

1 row created. 

SQL> select * from empview;

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME     DEPT_NO

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

Ravi               124 ECE                89

Vijay              345 CSE                21

Raj                 98     IT                 22

Giri                  100   CSE                67

Sri                120    CSE                67 

SQL> select * from employee; 


EMPLOYEE_N EMPLOYEE_NO DEPT_NAME     DEPT_NO DATE_OF_J

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

Ravi               124 ECE                89 15-JUN-05

Vijay              345 CSE                21 21-JUN-06

Raj                 98 IT                 22 30-SEP-06

Giri               100 CSE                67 14-NOV-81

Sri                120 CSE                67 16-NOV-81

SQL> delete from empview where employee_name='Sri'; 

1 row deleted.  SQL> select * from empview; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME     DEPT_NO

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

Ravi                 124   ECE                 89

Vijay                345   CSE                 21 

Raj                   98   IT                  22

Giri                 100   CSE                 67 

SQL> update empkaviview set employee_name='kavi' where employee_name='ravi'; 

0 rows updated. 

SQL> update empkaviview set employee_name='kavi' where employee_name='Ravi'; 

1 row updated. 

SQL> select * from empkaviview; 

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME     DEPT_NO

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

kavi               124 ECE                89

Vijay              345 CSE                21


Raj                 98 IT                 22

Giri               100 CSE                67 

SQL>drop view  empview;     

View droped   
 

RESULT:  
 

      Thus the SQL commands for View has been verified and executed successfully.   

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
EX: NO: 5A                                   

CURSOR

AIM:

      To write a Cursor Procedure to calculate Payroll process of an Employee. 

PROCEDURE:

      STEP 1: Start 

STEP 2: Initialize the Cursor Procedure based on the table attributes to which the actual
operation has to be carried out.  

      STEP 3: Develop the procedure with the essential operational parameters.

      STEP 4: Specify the Individual operation to be each attribute.

      STEP 5: Execute the Cursor procedure.

      STEP 6: Stop

EXECUTION:

SQL> create table salary(emp_no number(4) primary key,emp_name varchar2(30),designation 


varchar2(25),department varchar2(30),basic number(5),da_percent number(6,2), ma
number(6,2),other_allowances number(6,2),deduction number(6,2)); 

Table created. 
SQL> insert into Sal values (1,'vijay','manager','Accounts', 6000, 45, 200, 250, 1500.75); 

1 row created. 

SQL> insert into sal values (2,'vasanth','Asst.manager','Accounts', 4000, 45, 200, 200, 1200); 

1 row created. 

SQL> insert into Sal values (3,'priya','Steno','sales', 2000, 45, 100, 50,200);

1 row created. 

SQL> select * from sal; 

Emp_no   Emp_name  Designation    Department    Basic    da_percent   MA   other_allowance 


Deduction  

1       vijay         manager     Accounts    6000       45         200        250           1500.75    

2       vasanth     Asstmanager Accounts     4000       45         200        200             1200    

3       priya         Steno              sales           2000       45         100         50               200 

CODING

SQL> declare e_no number (6);

e_name varchar2 (25);

net_salary number(8,2);

cursor cur_salary is select emp_no,


emp_name,basic+da_percent*basic/100+ma+other_allowance-deduction from sal;

begin

dbms_output.put_line('emp no '||' Name '||' Net salary');


dbms_output.put_line('--------------------');  open cur_salary; loop fetch cur_salary into
e_no,e_name,net_salary;

exit when cur_salary%notfound;

dbms_output.put_line(rpad(e_no,10,' ')||rpad(e_name,25,' ')||net_salary);

end loop;

close cur_salary;

end;
/  

OUTPUT:  

emp no    Name         Net salary

1               vijay                7649.25     

2              vasanth             5000     

3              priya                 2850 

PL/SQL procedure successfully completed.        

RESULT:  
 

      Thus the Cursor Procedure for calculating the Payroll process has been executed
successfully. 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

 EX: NO: 5B                          

PROCEDURES

  AIM:

      To write a PL/SQL block to display the student name marks whose average mark is above
60%.   

PROCEDURE:

      STEP1: Start 

      STEP2: Create a table with table name stud_exam 

STEP3: Insert the values into the table and calculate total and average of each student              
STEP4: Execute the procedure function the student who get above 60%. 

      STEP5: Display the total and average of student 


      STEP6: End   

CODINGS 

SQL> create table student(regno number(4),name varchar2)20),mark1 number(3), mark2 


number(3), mark3 number(3), mark4 number(3), mark5 number(3));  

Table created 

SQL> insert into student values (101,'priya', 78, 88,77,60,89); 

1 row created.

SQL> insert into student values (102,'surya', 99,77,69,81,99); 

1 row created.

SQL> insert into student values (103,'suryapriya', 100,90,97,89,91); 

1 row created.

SQL> select * from student; 

regno    name       mark1 mark2  mark3  mark4  mark5  

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

101    priya              78     88      77         60           89      

102    surya              99    77      69         81           99      

103    suryapriya     100   90      97         89           91      

SQL>declare ave number(5,2); 

tot number(3);

cursor c_mark is select*from student where mark1>=40 and mark2>=40 and  mark3>=40 and
mark4>=40 and mark5>=40;

begin

dbms_output.put_line('regno name mark1 mark2 mark3 mark4 mark4 mark5 total average');
dbms_output.put_line('-------------------------------------------------------------');

for student in c_mark loop


tot:=student.mark1+student.mark2+student.mark3+student.mark4+student.mark5;
ave:=tot/5; dbms_output.put_line(student.regno||rpad(student.name,15) ||rpad(student.mark1,6)||
rpad(student.mark2,6)||rpad(student.mark3,6) ||rpad(student.mark4,6)||rpad(student.mark5,6)||
rpad(tot,8)||rpad(ave,5));

end loop;

end;

OUTPUT:

regno    name       mark1 mark2  mark3  mark4  mark5  total   average

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

101    priya              78     88      77         60           89      393      79

102    surya              99    77      69         81           99      425      85

103    suryapriya     100   90      97         89           91     467       93 

PL/SQL procedure successfully completed.  

RESULT:

      Thus the PL/SQL block to display the student name,marks,average is verified and executed. 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EX: NO: 5C          

FUNCTIONS

AIM:

      To write a Functional procedure to search an address from the given database. 

PROCEDURE:

      STEP 1: Start 

      STEP 2: Create the table with essential attributes.

      STEP 3: Initialize the Function to carryout the searching procedure..

      STEP 4: Frame the searching procedure for both positive and negative searching.

      STEP 5: Execute the Function for both positive and negative result .
      STEP 6: Stop

EXECUTION 

SQL> create table phonebook(phone_no number(6) primary key,username varchar2(30),doorno


varchar2(10), street varchar2(30),place varchar2(30),pincode char(6));

Table created.

SQL> insert into phonebook values(20312,'vijay','120/5D','bharathi street','NGO


colony','629002'); 

1 row created. 

SQL> insert into phonebook values(29467,'vasanth','39D4','RK bhavan','sarakkal


vilai','629002');  1 row created. 

SQL> select * from phonebook; 

PHONE_NO USERNAME   DOORNO     STREET            PLACE        PINCODE     

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

20312              vijay                  120/5D         bharathi street       NGO colony      629002 

29467            vasanth                39D4            RK bhavan           sarakkal vilai       629002    

CODING

SQL> create or replace function findAddress(phone in number) return varchar2 as                 


address varchar2(100);

begin

select username||','||doorno ||','||street ||','||place||','||pincode  into address from  phonebook       


where phone_no=phone;           

return address;

exception when no_data_found then

return 'address not found'; 

end;  

/ Function created. 

SQL>declare   
      address varchar2(100);  

      begin  

      address:=findaddress(20312);  

      dbms_output.put_line(address);  

      end;   

 /

OUTPUT:

vijay,120/5D,bharathi street,NGO colony,629002

PL/SQL procedure successfully completed.  

SQL> declare  

   ddress varchar2(100);  

   begin  

    ddress:=findaddress(23556);  

   dbms_output.put_line(address);  

   end;     

   / 

OUTPUT2:  

address not found

PL/SQL procedure successfully completed

.      

RESULT:  
      Thus the Function for searching process has been executed successfully.   
 
 
 
 
 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EX: NO: 5 D                                    

CONTROLS

AIM:

To write a PL/SQL block using different control (if else, for loop, while loop,…) statements.

 PROCEDURE:

      STEP 1: Start

      STEP 2: Initialize the necessary parameters.  

      STEP 3: Develop the set of statements with the essential operational parameters.

      STEP 4: Specify the Individual operation to be carried out.

      STEP 5: Execute the statements.

      STEP 6: Stop.

CODING

********************ADDITION OF TWO NUMBERS*********************** 

SQL> declare a number;

   number;

      c number;

      begin

      a:=&a;

      b:=&b;
      c:=a+b;

      dbms_output.put_line('sum of'||a||'and'||b||'is'||c);

      end;  

INPUT: 

Enter value for a: 23 old   6: a:=&a; new   6: a:=23; Enter value for b: 12 old   7: b:=&b; new   7:
b:=12; 

OUTPUT:

sum of 23and 12 is 35 

PL/SQL procedure successfully completed.   

*********** GREATEST OF THREE NUMBERS USING IF ELSE************* 

SQL> declare  a number;

      b number;

      c number;

      d number;

      begin a:=&a;

      b:=&b; 

      c:=&b;

      if(a>b)and(a>c)

      then dbms_output.put_line('A is maximum');   

      elsif(b>a)and(b>c)then

      dbms_output.put_line('B is maximum');

      else dbms_output.put_line('C is maximum');

      end if;

      end; 

INPUT: 

Enter value for a: 21

old   7: a:=&a;

new   7: a:=21;

Enter value for b: 12

old   8: b:=&b;

new   8: b:=12;

Enter value for b: 45

old   9: c:=&b;

new   9: c:=45; 

OUTPUT: 

C is maximum 

PL/SQL procedure successfully completed.           

 ***********SUMMATION OF ODD NUMBERS USING FOR LOOP*********** 

SQL> declare n number;

      sum1 number default 0;

      endvalue number;

      begin

      endvalue:=&endvalue; 

      n:=1;

      for n in 1..endvalue loop 

  if mod(n,2)=1 then

      sum1:=sum1+n;

      end if; 
      end loop;

      dbms_output.put_line('sum ='||sum1);

      end;  

INPUT: 

Enter value for endvalue: 4

old   6:

endvalue:=&endvalue;

new   6: endvalue:=4;

OUTPUT: 

  sum =4  

PL/SQL procedure successfully completed.                

 ***********SUMMATION OF ODD NUMBERS USING WHILE LOOP***********  


SQL> declare n number;

      sum1 number default 0;

      endvalue number;

      begin endvalue:=&endvalue;

      n:=1;

      while(n<endvalue) loop

      sum1:=sum1+n;

      n:=n+2;

      end loop;

      dbms_output.put_line('sum of odd no. bt 1 and' ||endvalue||'is'||sum1);

      end;


INPUT: 

Enter value for endvalue: 4

old   6: endvalue:=&endvalue;

new   6: endvalue:=4; 

OUTPUT: 

sum of odd no. bt 1 and 4is 4  

PL/SQL procedure successfully completed.             

RESULT:

      Thus the PL/SQL block for different controls are verified and executed.

 EX: NO: 6                 

FRONT END TOOLS

AIM:

      To design a form using different tools in Visual Basic. 

PROCEDURE:

      STEP 1: Start 

      STEP 2: Create the form with essential controls in tool box.

      STEP 3: Write the code for doing the appropriate functions.

      STEP 4: Save the forms and project.

      STEP 5: Execute the form.

      STEP 6: Stop

EXECUTION:

Form1

Private Sub Command1_Click () 

List1.AddItem Text1.Text

List1.AddItem Text2.Text
If Option1.Value = True Then

gender = "male"

End If

If Option2.Value = True Then

gender = "female"

End

If List1.AddItem gender List1.AddItem Text3.Text If Check1.Value = 1 And Check2.Value = 0


Then

area = "software Engineering"

End If

If Check1.Value = 1 And Check2.Value = 1 Then area = "software Engineering & Networks"


End If

If Check1.Value = 0 And Check2.Value = 1 Then area = “Networks"

End If 

List1.AddItem area List1.AddItem Text4.Text

End Sub 

Private Sub Command2_Click ()

If List1.ListIndex <> 0 Then

List1.RemoveItem (0)

End If

End Sub 

Private Sub Command3_Click ()

End

End Sub 

     
         RESULT:  
 

      Thus the program has been loaded and executed successfully.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  

EX: NO: 7                 

FORM DESIGN 

AIM:

      To design a form using Visual Basic. 

PROCEDURE:

      STEP 1: Start 

      STEP 2: Create the form with essential controls in tool box.

      STEP 3: Write the code for doing the appropriate functions.

      STEP 4: Save the forms and project.

      STEP 5: Execute the form.

      STEP 6: Stop

EXECUTION:

Form1

Private Sub Command1_Click ()

Dim a As Integer a = Val (Text1.Text) + Val (Text2.Text)

MsgBox ("Addition of Two numbers is" + Str(a))

End Sub   

Private Sub Command2_Click ()

Dim b As Integer b = Val (Text1.Text) - Val (Text2.Text)

MsgBox ("Subraction of Two numbers is" + Str(b))


End Sub   

Private Sub Command3_Click ()

Dim c As Integer c = Val(Text1.Text) * Val(Text2.Text)

MsgBox ("Multiplication of Two numbers is" + Str(c))

End Sub   

Private Sub Command4_Click () Dim d As Integer d = Val(Text1.Text) / Val(Text2.Text)


MsgBox ("Division  of Two numbers is" + Str(d)) 

End Sub  

Private Sub Command5_Click()

End

End Sub

 
 

RESULT: 

      Thus the program has been loaded and executed successfully.

  

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EX: NO: 8                         

TRIGGER

AIM:

      To develop and execute a Trigger for before and after update, delete, insert operations on a
table.    

PROCEDURE:

      STEP 1: Start 
      STEP 2: Initialize the trigger with specific table id. 

STEP 3: Specify the operations (update, delete, insert) for which the trigger has to be                
executed.

      STEP 4: Execute the Trigger procedure for both before and after sequences  

      STEP 5: Carryout the operation on the table to check for Trigger execution.

      STEP 6: Stop  

EXECUTION:

SQL> create table empa(id number(3),name varchar2(10),income number(4),expence


number(3),savings number(3)); 

Table created. 

SQL> insert into empa values(2,'kumar',2500,150,650);

1 row created. 

SQL> insert into empa values(3,'venky',5000,900,950); 

1 row created. 

SQL> insert into empa values(4,'anish',9999,999,999);

1 row created.      

SQL> select * from empa;

ID              NAME           INCOME    EXPENCE    SAVINGS

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

2                kumar            2500        150         650  

3                venky            5000         900         950   

4               anish             9999         999         999

TYPE 1- TRIGGER AFTER UPDATE

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

SQL> CREATE OR REPLACE TRIGGER EMP AFTER UPDATE OR INSERT OR DELETE


ON EMP FOR EACH ROW 
BEGIN

IF UPDATING THEN 

DBMS_OUTPUT.PUT_LINE ('TABLE IS UPDATED');

ELSIF INSERTING THEN

DBMS_OUTPUT.PUT_LINE ('TABLE IS INSERTED');

ELSIF DELETING THEN

DBMS_OUTPUT.PUT_LINE ('TABLE IS DELETED');

END IF;

END;

Trigger created. 

SQL> update emp set income =900 where empname='kumar';

TABLE IS UPDATED 1 row updated. 

SQL> insert into emp values ( 4,'Chandru',700,250,80);

TABLE IS INSERTED

1 row created. 

SQL> DELETE FROM EMP WHERE EMPID = 4;

TABLE IS DELETED

1 row deleted. 

SQL> select * from emp;    

EMPID EMPNAME       INCOME   EXPENSE   SAVINGS  

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

2              vivek                  830               150             100        

3              kumar               5000               550               50        

9              vasanth               987             6554             644    


TYPE 2     - TRIGGER BEFORE UPDATE

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

SQL> CREATE OR REPLACE TRIGGER VASANTH BEFORE UPDATE OR INSERT OR


DELETE ON EMPLOYEE FOR EACH ROW

BEGIN

IF UPDATING THEN

DBMS_OUTPUT.PUT_LINE ('TABLE IS UPDATED');

ELSIF

INSERTING

THEN

DBMS_OUTPUT.PUT_LINE('TABLE IS INSERTED');

ELSIF DELETING

THEN DBMS_OUTPUT.PUT_LINE ('TABLE IS DELETED');

END IF;

END;

Trigger created. 

SQL> INSERT INTO EMP VALUES (4,'SANKAR',700,98,564);

TABLE IS INSERTED 

1 row created. 

SQL> UPDATE EMP SET EMPID = 5 WHERE EMPNAME = 'SANKAR';

TABLE IS UPDATED 

1 row updated. 

SQL> DELETE EMP WHERE EMPNAME='SANKAR';

TABLE IS DELETED 
1 row deleted.            
 
 
 

RESULT: 

      Thus the Trigger procedure has been executed successfully for both before                     and
after sequences. 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  

EX: NO: 9                 

MENU DESIGN

AIM:

      To design a menu using Visual Basic.   

PROCEDURE:

      STEP 1: Start 

      STEP 2: Create the form with essential controls and insert the menu using menu editor.

      STEP 3: Write the code for doing the appropriate functions.

      STEP 4: Save the forms and project.

      STEP 5: Execute the form.

      STEP 6: Stop

CODING: 

Form 1: 

Private Sub mapple_Click()

MsgBox ("You selected Apple")

End Sub   

Private Sub mblue_Click()


MsgBox ("You selected Blue color")

End Sub   

Private Sub mcircle_Click()

MsgBox ("You selected Circle")

End Sub   

Private Sub mexit_Click() End

End Sub   

Private Sub mgrapes_Click()

MsgBox ("You selected Grapes")

End Sub   

Private Sub mgreen_Click()

MsgBox ("You selected Green color ") 

End Sub   

Private Sub morange_Click()

MsgBox ("You selected Orange")

End Sub   

Private Sub mrectangle_Click()

MsgBox ("You selected Rectangle")

End Sub   

Private Sub mred_Click()

MsgBox ("You selected Red color")

End Sub   

Private Sub mtriangle_Click()

MsgBox ("You selected Triangle")

End Sub 
    

   

RESULT:  

      Thus the program for menu creation with menu editor has been developed and executed
successfully.  

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EX: NO: 10                 

REPORT GENERATION

AIM:

      To design a report for employee database using Visual Basic. 

PROCEDURE:

      STEP 1: Start

      STEP 2: Create the form with essential controls for employee details.

      STEP 3: Insert the data environment for report generation

      STEP 4: Connect the database 

      STEP 5: Write the code for doing the appropriate operations in the employee database.

      STEP 6: Save the forms and project.

      STEP 7: Execute the form.

      STEP 8: Stop

EXECUTION MAIN FORM CODE:

Private Sub Command1_Click ()

Unload Me

Form1.Visible = False

Form2.Visible = True
Load Form2 Form2.Show

End Sub   

Private Sub Command2_Click ()

Unload Me

Form1.Visible = False

Form3.Visible = True

Load Form4 Form3.Show

End Sub   

Private Sub Command3_Click ()

Unload Me

Form1.Visible = False 

Form4.Visible = True

Load Form3 Form4.Show

End Sub  

Private Sub Command4_Click ()

End

End Sub   

Private Sub Command5_Click ()

DataReport1.Show

End Sub

FORM2

CODING: 

General Declaration

Dim con As New ADODB.Connection Dim gp, ded, net As Double


Private Sub Command1_Click ()

gp = Val(Combo1.ItemData(Combo1.ListIndex)) + Val(Text7.Text) ded = Val(Text4.Text) +


Val(Text5.Text) + Val(Text6.Text)

net = gp - ded con.Execute "insert into emp values('" & Text1.Text & "','" & Text2.Text & "','" &
Combo1.Text & "','" & Text3.Text & "','" & Val(Combo1.ItemData(Combo1.ListIndex)) & "','"
& Val(Text4.Text) & "','" & Val(Text5.Text) & "','" & Val(Text6.Text) & "','" &
Val(Text7.Text) & "','" & gp & "','" & net & "',0)"

MsgBox ("Records Created!!!!!!!!!!!")

Unload Form2

Load Form1 Form1.Show

End Sub 

Private Sub Form_Load ()

con.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Program Files\Microsoft Visual


Studio\VB98\subbu\employee.mdb;Persist Security Info=False"

End Sub 

Private Sub Form_Unload (Cancel As Integer)

con.Close

End Sub

FORM3:

UPDATION CODE:

General Declaration

Dim con As New ADODB.Connection

Dim rs As New ADODB.Recordset 

Dim n As Double   

Private Sub Command1_Click()


rs.Open "select * from emp where id='" & Text1.Text & "'", con n = rs.Fields(10) +
Val(Text2.Text) con.Execute "update emp set others='" & Val(Text2.Text) & "',net_salary='" &
n & "' where id='" & Text1.Text & "'"

MsgBox ("Records Updated!!!!!!!!!!!!!")

Unload Form3

Load Form1 Form1.Show

End Sub   

Private Sub Form_Load()

con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual


Studio\VB98\subbu\employee.mdb;Persist Security Info=False"

End Sub

Private Sub Form_Unload(Cancel As Integer)

con.Close

End Sub 

FORM4:

DISPLAY CODE: 

General Declaration

Dim con As New ADODB.Connection

Dim rs As New ADODB.Recordset

Dim num As String   

Private Sub Command1_Click ()

num = Text1.Text rs.Open "select * from emp where id='" + num + "'", con Set
DataReport1.DataSource = rs DataReport1.Show

End Sub

Private Sub Form_Load ()


con.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Program Files\Microsoft Visual
Studio\VB98\subbu\employee.mdb;Persist Security Info=False"

End Sub   

Private Sub Form_Unload (Cancel As Integer)

con.Close

End Sub 

EX: NO: 11                

PAYROLL PROCESSING SYSTEM

AIM:

      To develop an application software for Payroll processing of an organization.

DESIGN PLAN:

The Design plan consists of the following:

Project Plan

Software requirement Analysis

Implementation and Coding

Software testing

Software Debugging

Conclusion

PROJECT PLAN:

   The Project plan consists of three sections: 

Personal Details of an employee 

Allowances 

Deduction and Checking the increement and Net pay  


SOFTWARE REQUIREMENT ANALYSIS:    

      The purpose of the Payroll as to provide Payroll for the Employee with allowance and    
deduction individually and to update the Net pay.

Functionality of System:    

1. Personal Details of an Employee

         It includes Employee Name, Employee id, Address, Designation and Date of Birth.     

 2. Allowance:

      DA refers to Dearness Allowance, TA refers to Traveling Allowance, HRA refers to House
Rent Allowance, and MA refers to Medical Allowance.  3.

 3. Deduction:

        PF refers to Provident Fund. LIC refers to Life Insurance Corporation, Vehicle Loan 

SOFTWARE TESTING: 

      The main objectives of testing to maximize the test case, minimize the number of errors,
focus on correctness and efficiency of program. It helps to find out details of the employee and
their personal details, experience with total salary.  Allowances and Deductions are calculated
from GROSS amount.

CODING:

FORM 1:

Private Sub Command1_Click()

Unload Me

Form2.Show

End Sub 

Private Sub Command2_Click()

Unload Me

Form3.Show

End Sub 

Private Sub Command3_Click()


Unload Me Form4.Show

End Sub 

Private Sub Command4_Click()

End

End Sub   
 
 

Private Sub Command5_Click()

Unload Me

Form5.Show

End Sub  

FORM 2:  

Private Sub Command1_Click()

Adodc1.Recordset.AddNew Adodc1.Recordset.Fields("e_name") = Text1.Text


Adodc1.Recordset.Fields("e_no") = Val(Text2.Text)

Adodc1.Recordset.Fields("des") = Text3.Text

Adodc1.Recordset.Fields("age") = Val(Text4.Text)

Adodc1.Recordset.Fields("sex") = Text5.Text

Adodc1.Recordset.Fields("dob") = Val(Text6.Text)

Adodc1.Recordset.Fields("doj") = Val(Text7.Text)

Adodc1.Recordset.Fields("sal") = Val(Text8.Text)

Adodc1.Recordset.Fields("ph") = Val(Text9.Text)

Adodc1.Recordset.Fields("e_mail") = Text10.Text '

Adodc1.Recordset.Update

End Sub   

Private Sub Command2_Click()


Adodc1.Recordset.Fields("e_name") = Text1.Text

Adodc1.Recordset.Update

End Sub   

Private Sub Command3_Click()

a = InputBox("Enter the Employee Number", Emp_no)

Adodc1.Recordset.MoveFirst On Error

GoTo diva While Not Adodc1.Recordset.Fields("e_no") = Val(a)

Adodc1.Recordset.

MoveNext

Wend diva:

End Sub   

Private Sub Command4_Click()

b = MsgBox("Are you sure you want to delete it....", vbOKCancel + vbExclamation)

If b = 1 Then

Adodc1.Recordset.Delete

Adodc1.Recordset.MoveNext

MsgBox "Record is Deleted"

Else

End If

End Sub   

Private Sub Command5_Click()

Unload Me

Load Form1: Form1.Visible = True

End Sub   

FORM 3:
Dim c As Variant Private Sub Command1_Click()

Adodc1.Recordset.AddNew Adodc1.Recordset.Fields("e_name") = Text1.Text


Adodc1.Recordset.Fields("e_no") = Val(Text2.Text)

Adodc1.Recordset.Fields("sal") = Val(Text3.Text)

Adodc1.Recordset.Fields("loan") = Val(Text4.Text)

Adodc1.Recordset.Fields("loan_left") = Val(Text5.Text)

Adodc1.Recordset.Fields("ma") = Val(Text6.Text)

Adodc1.Recordset.Fields("hra") = Val(Text7.Text)

Adodc1.Recordset.Fields("ins_left") = Val(Text8.Text)

Adodc1.Recordset.Fields("da") = Val(Text9.Text)

Adodc1.Recordset.Fields("total_allow") = Val(Text10.Text)

'adodc1.Recordset.Update

End Sub   

Private Sub Command2_Click()

Adodc1.Recordset.Fields("e_name") = Text1.Text

Adodc1.Recordset.Update

End Sub   

Private Sub Command3_Click()

a = InputBox("Enter the Employee Number", "Diva")

Adodc1.Recordset.MoveFirst

On Error GoTo diva

While Not Adodc1.Recordset.Fields("e_no") = Val(a)

Adodc1.Recordset.MoveNext

Wend diva:

End Sub   
Private Sub Command4_Click()

b = MsgBox("Are you sure you want to delete it....", vbOKCancel + vbCritical, "Diva")

If b = 1 Then Adodc1.Recordset.Delete

Adodc1.Recordset.MoveNext

MsgBox "Record is Deleted"

Else

End If

End Sub   

Private Sub Command5_Click()

Unload Me

Load Form1: Form1.Visible = True

End Sub 

Private Sub Form_Load()

c = (Val(Text6.Text) + Val(Text7.Text) + Val(Text9.Text))

Text10.Text = c

Adodc1.Recordset.Fields("e_name") = Text1.Text

Adodc1.Recordset.Update

End Sub   

Private Sub Text3_Change()

x = Val(Text3.Text) Text6.Text = (x / 2) Text7.Text = (x / 3) Text9.Text = (x / 4) c =


(Val(Text6.Text) + Val(Text7.Text) + Val(Text9.Text))

Text10.Text = c

Adodc1.Recordset.Fields("e_name") = Text1.Text

Adodc1.Recordset.Update
End Sub   

FORM 4:

Dim c As Variant Private Sub Command1_Click()

Adodc1.Recordset.AddNew

Adodc1.Recordset.Fields("e_name") = Text1.Text

Adodc1.Recordset.Fields("e_no") = Val(Text2.Text)

Adodc1.Recordset.Fields("sal") = Val(Text3.Text)

Adodc1.Recordset.Fields("spf") = Val(Text4.Text)

Adodc1.Recordset.Fields("fa") = Val(Text5.Text)

Adodc1.Recordset.Fields("hf") = Val(Text6.Text)

Adodc1.Recordset.Fields("hr") = Val(Text7.Text)

Adodc1.Recordset.Fields("income_tax") = Val(Text8.Text)

Adodc1.Recordset.Fields("others") = Val(Text9.Text)

Adodc1.Recordset.Fields("total_ded") = Val(Text10.Text)

'adodc1.Recordset.Update

End Sub   

Private Sub Command2_Click()

Adodc1.Recordset.Fields("e_name") = Text1.Text

Adodc1.Recordset.Update

End Sub

Private Sub Command3_Click()

a = InputBox("Enter the Employee Number", "Diva")

Adodc1.Recordset.MoveFirst On Error GoTo diva While Not Adodc1.Recordset.Fields("e_no")


= Val(a) 
Adodc1.Recordset.MoveNext

Wend diva:

End Sub   

Private Sub Command4_Click()

b = MsgBox("Are you sure you want to delete it....", vbOKCancel + vbCritical, "Diva")

If b = 1 Then Adodc1.Recordset.Delete

Adodc1.Recordset.MoveNext

MsgBox "Deleted"

Else

End If

End Sub

Private Sub Command5_Click()

Unload Me Load Form1: Form1.Visible = True

End Sub  

Private Sub Form_Load()

x = Val(Text3.Text)

Text4.Text = (x / 0.2)

Text5.Text = (x / 0.2)

Text6.Text = (x / 0.2)

Text7.Text = (x / 0.2)

Text8.Text = (x / 0.2)

Text9.Text = (x / 0.2)

c = (Val(Text4.Text) + Val(Text5.Text) + Val(Text6.Text) + Val(Text7.Text) + Val(Text8.Text)


+ Val(Text9.Text))

Text10.Text = c
Adodc1.Recordset.Fields("e_name") = Text1.Text

Adodc1.Recordset.Update

End Sub 

Private Sub Text2_Change ()

c = (Val (Text4.Text) + Val(Text5.Text) + Val(Text6.Text) + Val(Text7.Text) + Val(Text8.Text)


+ Val(Text9.Text))

Text10.Text = c

End Sub   

Private Sub Text3_Change ()

x = Val (Text3.Text)

Text4.Text = (x / 0.2)

Text5.Text = (x / 0.2)

Text6.Text = (x / 0.2)

Text7.Text = (x / 0.2)

Text8.Text = (x / 0.2) 

Text9.Text = (x / 0.2)

Adodc1.Recordset.Fields ("e_name") = Text1.Text

Adodc1.Recordset.Update

End Sub   

FORM 5:

Private Sub Command1_Click ()

Unload Me

Load Form1: Form1.Visible = True

End Sub 

Private Sub Command2_Click ()


End

End Sub   

Private Sub Command3_Click ()

a = InputBox("Enter the Employee Number", "Diva") Adodc1.Recordset.MoveFirst On Error


GoTo diva While Not Adodc1.Recordset.Fields("e_no") = Val(a)

Adodc1.Recordset.MoveNext Wend diva:

End Sub   

Private Sub Form_Load ()

Adodc1.Recordset.Fields ("e_name") = Text1.Text

Adodc1.Recordset.Update

End Sub   

Private Sub Text1_Change ()

b = Val (Text3.Text) + Val (Text4.Text) c = b - Val (Text5.Text)

Text6.Text = c

End Sub     

 
 
 
 
 
 
 
 
 
 
 

Result:      

      Thus the payroll processing system is designed and implemented in VB and output is
verified.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  

You might also like