You are on page 1of 2

Ex.

No: 8 Views in SQL


Name Type Remark
ID Number(5) Primary Key
Name Varchar(10)
Age Number(2)
Designation Varchar(15)
Salary Number(10)
Create Table
SQL>Create table employee(id number(5), name varchar(10), age number(2), designation
varchar(15),salary number(10));
Table Created.
Describe Table
SQL>desc employee;
Name Null Type
-----------------------------------------------------
ID Number(5)
Name varchar(10)
Age Number(2)
Designation varchar(15)
Salary number(10)

Insert Values
SQL>insert into employee values(id,’&name’,age,’&designation’,salary);
Enter value for id:101
Enter value for name:Ramesh
Enter value for age: 35
Enter value for designation:Manager
Enter value for salary: 45000
1 row created
SQL>/
Table Retrieval

SQL>select * from employee;

ID Name Age Designation Salary


------------------------------------------------------------------------
101 Ramesh 35 Manager 45000
102 Subha 22 Asst.Manager 40000
103 Reshma 30 Deputy Manager 30000
104 John 50 Manager 75000

Querries
1. Create a view emp that contains name, age, designation, salary. Also describe the structure
of the view.
SQL>Create view emp as select id, name, age, designation, salary from employee;
View Created
SQL>desc emp;

2. Display the contents of the view

SQL>select * from emp;

3. Update the view emp by increasing10% salary of the employees who work as ‘Deputy
Manager’. Also confirm the modifications in employee table.

SQL>update emp set salary=salary +0.10*salary where designation=’Deputy Manager’;

1 row updated

SQL>Select * from employee;

4. Update the age of Ramesh as 40.

SQL>update emp set age=40 where name=’Ramesh’;

1 row updated

SQL>Select * from emp;


5. Display the name of employee in upper case

SQL> select upper(name) from emp;

6. Display the designation of employees in lower case.

SQL> select lower(name) from emp;

7. Calculate the annual salary of employees and display with ID, name and designation.

SQL> select id, name, designation, salary*12 from emp;

8. Delete a record having age=50.


SQL> delete from emp where age=50;
I row deleted
SQL>Select * from emp;

SQL>Select * from employee;

You might also like