You are on page 1of 7

Experiment No:- 7

Aim: Implementation of views.


1. Creation of views
2. Usage of views
3. Creation of views using views
4. Drop view
Resources used: SQL Server 2000.
Theory:
Views: Any relation that is not part of any logical model but is made visible to the user
as a virtual relation is called as a view. It is possible to support a large number of views
on the top of any given set of actual database relation. Views help in 2 ways:
1. For security purpose
2. Create a personalized collection of relation that is better users intuition than is
logical model
Creation of Views:
1. Views is defined using create view command
2. to define a view we must give the view a better name and must state the query
that computes the view.
Syntax:
create view<view name> as <query expression>
Where query expression is any legal query expression.
3. Once we have defined a view, we can use the view name to refer to the virtual
relation that the view generation .
4. Attribute name of the view can be specified explicitly as :
Create view v(VA1, VA2,..VAn) as select (A1,A2..,An) from r1 where(p)
Where, p: predicate
R1: relation
A1-An:attribute of view
V: view name
Creation of views using views
Since, view relations may appear in any place that a relation name may appear, except
for restrictions on the use of views in update expressions. Thus, one view may be used
in the expression defining another view. For eg. Let Emp_work_info is a view with

attribute F_name, SSN, Project_no, Work_hrs. Then creation of other view can be done
as
create view new_view
select f_name, work_hrs
from emp_work_info
Updating of views
Although views are useful for the queries they present a serious problem. If we express
updates insertion or deletion on view as the modification done to the database in terms
of the views must be translated to a modification to actual relations in the logical
methods of database,
Drop view
A view creates earlier can be dropped using Drop View command
Syntax: Drop view r
Where: r: View Name
It deletes all the information about view from the database.
Conclusion: Thus we have concluded the project by studying and implementing the
concept of views in SQL.

Experiment No:-8
Aim : To create queries using Triggers
Resources used: SQL Server 2000.
Theory: Create trigger:
Arguments:
1. Trigger name: Name of the trigger must confirm to the rules for identifier and
must be unique within the databases specifying the trigger. Owner name is
optional.
2. Table view: It is the table or the view on which the trigger is executed and is
sometimes called trigger table or view.
3. Instead of: Specifies that the trigger is executed in place of triggering SQL
statement thus overriding the actions of the triggering statements. At most one
instead of trigger per INSERT, UPDATE or DELETE statement can be defined on
a table or view INSTEAD OF triggers are not allowed on the updatable views with
check option. SQL server will raise on error if an INSTEAD OF trigger is added
to an updatable view with check option specified. The user must remove that
option using ALTER VIEW before defining the INSTEAD OF trigger.
4. AS: Are the actions the trigger is to perform.
5. SQL- stmt: Is the trigger condition(s) and action(s)
-

deleted and inserted as logical tables. They are structurally similarly to the
table on which the trigger is defined i.e. the table on which the user action
is attempted.
Example: select * from deleted

6. Trigger limitations: Create trigger must be the first stmt in the batch and can
apply to only one table.
7. Create Trigger: A trigger is created only in the current database however it can
reference objects the current database.
8. Multiple triggers: SQL server allows multiple triggers to be created for each data
modification event.
Conclusion: Thus we have successfully implemented triggers

Experiment No:- 9
Aim : To implement queries using Procedures.
Resources used: SQL Server 2005.
Theory: Create Procedure:
A stored procedure is a subroutine available to applications accessing a relational
database system. Stored procedures (sometimes called a proc, sproc, StoPro, or SP)
are actually stored in the database data dictionary.
Typical uses for stored procedures include data validation (integrated into the
database) or access control mechanisms. Furthermore, stored procedures are used to
consolidate and centralize logic that was originally implemented in applications. Large
or complex processing that might require the execution of several SQL statements is
moved into stored procedures, and all applications call the procedures only.
Stored procedures are similar to user-defined functions (UDFs). The major difference
is that UDFs can be used like any other expression within SQL statements, whereas
stored procedures must be invoked using the CALL statement
CALL procedure() or
EXECUTE procedure()
Stored procedures can return result sets, i.e. the results of a SELECT statement. Such
result sets can be processed using cursors by other stored procedures by associating a
result set locator, or by applications. Stored procedures may also contain declared
variables for processing data and cursors that allow it to loop through multiple rows in a
table. The standard Structured Query Language provides IF, WHILE, LOOP, REPEAT,
CASE statements, and more. Stored procedures can receive variables, return results or
modify variables and return them, depending on how and where the variable is declared
Procedure Declaration:
create PROCEDURE
CREATE PROC procedure_name
[number]
[{@parameter data_type}
[varying] [=default][OUTPUT]]
[---n]
[with {RECOMPILE/ENCRYPTION/RECOMPILE,ENCRYPTION}]
[FOR REPLICATION]
AS SQL_stmt[---n]
-Arguments: Procedure_name is the neme of the new procedure stored.
-As: Specifies the actions the procedure is to take

-Remarks: The max size of a stored procedure is 128 MB.


-n: Is a placeholder that indicates multiple transact SQL statements may
be included in this procedure.
Alter Procedure:
Syntax: ALTER PROC procedure_name[number]
[{@parameter data_type}
[VARYING][=default][OUTPUT]
][---n]
[WITH
{RECOMPILE?ENCRYPTION?RECOMPILE,ENCRYPTION}
]
[FOR REPLICATION]
AS
Sq_stmt[---n]
Drop Procedure:
Removes one or more stored procedures or procedure groups from the
current Data Base.
Syntax: DROP PROCEDURE {procedure_name}[---n]
Conclusion : Thus we have successfully implemented procedures.

Experiment No:- 10
Aim : To implements ORDBMS concepts.
Resources used: SQL Server 2005.
Theory: In Oracle 9i there are different features of Oracle databases:
1. Relational DB: The traditional DB(RDBS).
2. Object Relational DB: The traditional relational database executed to includes
object concept and structure as abstract nested tables and varying array.
3. Object types available in Oracle
- Abstract datatype: They are data types that consists of one or more subtypes.
They are data types i.e. data type that uses additional information you can create
a table that uses abstract datatypes for addresses.
4. Nested Table: A nested table is a collection of four rows represented as columns
within main table, may contain multiple rows.
5. Extending the object oriented terminology further the individual components of an
oracle abstract data type are referred to as attributes in this example:
Create Table Personnel( EMPL_NUM INTEGER
NAME NAME_TYPE
ADRESS ADDR_TYPE);
Oracle uses extended dot notation to refer to individual data elements within abstract
data types. With nested abstract data_types, it takes several levels at dot delemented
names to identify an individual data item.
The main postal code within personnel table as
PERSONNEL.ADDRESS.POSTALCODE
You can define PERSONNEL.table using row type as model
Create Table PERSONNEL
OF TYPE PERSONNEL.TYPE
The columns of this PERSONNEL table will be exactly as they were in previous
CREATE TABLE Examples but now personnel is a typed table.
6. Varying Arrays: A varying array is a set of objects within the same data type. The
size of array is limited when it is created.
7. Creating Abstract Datatype:\
SQL> create a replace types add by object (street verchar(50); city varchar(25);
state varchar(20);)
Creating table using abstract data type:
SQL>create table CUSTOMER(customer_idno);

Inserting records:
SQL>Insert into table name value(value);
Selecting records from abstract data type:
Consider name of person abstract data type of customer table
Deleting records from abstract data type:
SQL>delete from CUSTOMER a
Where a person.name=abc;
Deleting Object types
SQL>DROP ype Person
Type can be drop only if it has not been used in any object type
Conclusion: Thus we have executed the SQL statements which responds to the
users query.

You might also like