17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

you are essentially saying to <strong>SQL</strong> <strong>Server</strong>: “Give me all of the rows and columns you get when you run<br />

the statement SELECT CustomerName, Contact, Phone FROM Customers.”<br />

We’ve created something of a pass-through situation — that is, our view hasn’t really changed anything,<br />

but rather just “passed through” a filtered version of the data it was accessing. What’s nice about that is<br />

that we have reduced the complexity for the end user. In this day and age, where we have so many tools<br />

to make life easier for the user, this may not seem like all that big of a deal — but to the user, it is.<br />

Let’s go with another view that illustrates what we can do in terms of hiding sensitive data. For this<br />

example, let’s go back to our Employees table in our Accounting database (we’ll create a special version<br />

of the now familiar Accounting database a little later in the chapter). Take a look at the table layout:<br />

Employees<br />

EmployeeID<br />

FirstName<br />

MiddleInitial<br />

LastName<br />

Title<br />

SSN<br />

Salary<br />

HireDate<br />

TerminationDate<br />

ManagerEmpID<br />

Department<br />

Chapter 10: Views<br />

Be aware that, by default, there is nothing special done for a view. The view runs<br />

just as if it were a query run from the command line — there is no pre-optimization<br />

of any kind. This means that you are adding one more layer of overhead between<br />

the request for data and the data being delivered, and thus, that a view is never<br />

going to run as fast as if you had just run the underlying SELECT statement directly.<br />

That said, views exist for a reason — be it security or simplification for the user —<br />

balance your need against the overhead as would seem to fit your particular situation.<br />

Federal law in the U.S. protects some of this information — we must limit access to a “need to know”<br />

basis. Other columns, however, are free for anyone to see. What if we want to expose the unrestricted<br />

301

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!