Database Reference
In-Depth Information
CREATE VIEW vw_customers
AS
SELECT
objid
,email
,customer_id
,firstname
,lastname
,homephone
,workphone
,mobilephone
FROM tbl_customer
Notice that the customer view is very simple and returns most of the
data from tbl_customer. The only thing left out is web_password, because
it was determined that this is a special column and needs to be seen only
in rare instances. Next, let's look at the code for the customer addresses
view.
CREATE VIEW vw_customer_addresses
AS
SELECT
address_objid = objid
,address_label
,addressline1
,addressline2
,city
,region
,zipcode
,customer_objid
FROM tbl_address
WHERE customer_objid IS NOT NULL
This view will be similar to vw_customer, which we created earlier, but
there are a few key differences. Because vw_customer_addresses returns
multiple columns containing objid data from what amounts to the data
from different tables, we alias the objid column from tbl_address to address_
objid. In this way, there is no confusion about which objid we are talking
about.
Second, because tbl_address can hold addresses for either a customer
or an employee, we select only rows in which the customer_objid does not
Search WWH ::




Custom Search