Glowie
Glowie

Reputation: 2309

How to use VIEWS in SQL Queries

We have third party software that installed SQL database so we can create custom queries.

They also have views which includes values, such as VIRUSNAME that the Tables does not have.

So far, I find tutorials on how to create views, but where do I find tutorials on how to use views in an SQL query?

enter image description here

Upvotes: 0

Views: 37037

Answers (3)

user63762453
user63762453

Reputation: 1734

You might want to look at a tutorial from TutorialsPoint.

Contains most of the things you need to know about views.

A few more are:

From code project: How to create,update,delete a view

From w3 schools:How to create,update,delete a view(with great examples)

From microsoft technet:Scenarios for Using Views

Use of a View

Views are generally used to focus, simplify, and customize the perception each user has of the database.Views can be used for security purposes because they provide encapsulation of the name of the table. Data is in the virtual table, not stored permanently. Views display only selected data.

The syntax for creating a View is given below:

Create View Viewname As
 Select Column1, Column2  From Tablename   Where (Condition) Group by (Grouping Condition) having (having Condition) For example:

 Create View View_Employeeinfo As s
    Select EmpId, EmpName, employmentdate  From EmployeeInfo 

Now user can use the view View_EmployeeInfo as a table to get the empid, empname and employmentdate information of the employees by using the following query:

 Select  *   from  View_EmployeeInfo  where empid=3 

Others uses:

  1. Views let users focus on specific data that interests them and on the specific tasks for which they are responsible. Unnecessary or sensitive data can be left out of the view.

  2. Views can simplify how users work with data. You can define frequently used joins, projections, UNION queries, and SELECT queries as views so that users do not have to specify all the conditions and qualifications every time an additional operation is performed on that data.

  3. Views enable you to create a backward compatible interface for a table when its schema changes.

  4. Views let different users to see data in different ways, even when they are using the same data at the same time.

  5. Views can be used to export data to other applications.

  6. The Transact-SQL UNION set operator can be used within a view to combine the results of two or more queries from separate tables into a single result set. This appears to the user as a single table that is called a partitioned view.

Upvotes: 3

Rushi
Rushi

Reputation: 7

Well, you use the views to fetch data just like the way you do the same from tables.

http://www.java2s.com/Tutorial/Oracle/0160__View/Performselectoncolumnsinaview.htm

hope this is what you wanted!

Upvotes: -2

Orlando Herrera
Orlando Herrera

Reputation: 3531

First off, take a look in this interesting post What are views good for?

SQL CREATE VIEW Syntax

CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition

Calling a VIEW

SELECT * FROM [Name of your VIEW]

Finally, I can give you this basic link Introduction to Sql Server Views

Upvotes: 4

Related Questions